First off you're welcome for the added easing option. you can choose from many. They're listed here:
https://api.jqueryui.com/easings/
As for your other question, you can just do what you show. It works as animation. But unlike simply changing the width, animation occurs over time, so doing more than one of them at once is trickier. And you need to handle what to do if an opposite animation is called for before the current one is finished. Even that said, most of the differences between your code and mine are what I consider best practices, and have little to do with animation. Most just have to do with how I write code, things like minimizing lookups and protecting variables.
And here's a minor improvement:
Code:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
.hovericons{overflow:hidden; background-color: #f00; width:800px;}
.hovericons p{background-color:#FFCC66; font-size:18px; font-family:Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:center;
padding:0px; float:left; height:36px; line-height:26px; margin:0; display:block;}
.hovericons p:hover{background-color:olive;}
.hovericons p a{color:#FFFFFF; text-decoration:none; display:block; border-left:1px solid #FFFFFF; text-align:center; width:88px; padding:5px; margin:0;
height:36px}
.hovericons p:first-child a{width:488px;}
</style>
</head>
<body>
<div class="hovericons">
<p><a href="#">1<span class="ttext">first</span></a></p>
<p><a href="#">2<span class="ttext">second</span></a></p>
<p><a href="#">3<span class="ttext">third</span></a></p>
<p><a href="#">4<span class="ttext">fourth</span></a></p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var ttxt = $(".ttext").hide().first().show().end(), first = $('.hovericons p:first-child a'), timer, trantime = 800,
ease = 'easeOutBack', firsttext = first.find('.ttext'), thistext, iconsa = $(".hovericons a").mouseenter(function(){
clearTimeout(timer);
thistext = $(this).find('.ttext').fadeIn();
ttxt.not(thistext).stop(true, true).hide();
iconsa.stop().not(this).animate({width: 88}, trantime, ease);
$(this).animate({width: 488}, trantime, ease);
}).mouseleave(function(){
timer = setTimeout(function(){
firsttext.fadeIn();
ttxt.not(firsttext).stop(true, true).hide();
iconsa.stop().not(first).animate({width: 88}, trantime, ease);
first.animate({width:488}, trantime, ease);
}, 100);
});
});
</script>
</body>
</html>
The stop() function allows us to interrupt any transition on the selected elements and (if desired) perform another. It's really just a game of telling it what you want it to do. If you like, I could give you a documented version that might make things clearer. Let me know.
Bookmarks