Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I upvoted the answer by @jimjimmy1995, but just to provide an alternative way of doing the same animation which will be faster and more efficient:</p> <pre><code>$('#icons').on({ mouseenter:function(){ $(this).stop().animate({top:(-1*hover_distance)},hover_speed); }, mouseleave:function(){ $(this).stop().animate({top:0},hover_speed); } },'li'); </code></pre> <p>The only differences are:</p> <ol> <li>The use of <code>.on()</code> is more transparent, but also allows for more extensibility (you can add more on events later, like <code>mousemove</code> or something, if you want)</li> <li>Delegation of all <code>li</code> from <code>#icons</code> rather than making <code>#icons &gt; li</code> the selector means the animation binding is only applied once, rather than many times (one time for each <code>li</code>) - this is the most important of the three changes</li> <li>Using the native DOM name rather than the string (<code>top</code> vs <code>'top'</code>) is a best practice. It makes no difference for non-hyphenated words, but when you start dealing with <code>marginTop</code> vs <code>'margin-top'</code> it makes a difference.</li> </ol> <p><strong>UPDATE</strong></p> <p>Found the solution:</p> <pre><code>$('#icons').on({ mouseenter:function(){ if(!$(this).is(':animated')){ $(this).animate({top:(-1*hover_distance)},hover_speed); } }, mouseleave:function(){ $(this).animate({top:0},hover_speed); } },'li'); </code></pre> <p>Using the <a href="http://api.jquery.com/animated-selector/" rel="nofollow">:animated selector</a> checks if the item is in progress of being animated. The if logic will only perform the animation if it is not.</p> <p><a href="http://jsfiddle.net/nZqLy/8/" rel="nofollow">jsFiddle to prove it</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload