Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate relative position (on hover) bug,

Whenever the following code is run in Chrome and FF (not tested in other browsers), the "text" goes as such , as in the image. The script is supposed to lift the "text" 4px above on mouseover and return it back on mouseout

But instead when the mouse is brought in the motion as below, each time it lifts 4px above to its last position.

$(document).ready(function(){
    $('#n #c a').hover(function(){
        $('span',this).stop(true,true).animate({top:'-=4px'},200);
    },function(){
        $('span',this).stop(true,true).animate({top:'+=4px'},400);
    });
});

Follow the steps as such, it should be quick!

NOTE : In above image the text is just one, others are shown for understanding purpose. You have to be quick to catch the same effect.

like image 361
Suraj Avatar asked Mar 22 '26 09:03

Suraj


1 Answers

I think you can just set the top to -4px on hover and 0px when the mouse exists

$(document).ready(function(){
    $('#n #c a').hover(function(){
        $('span',this).stop(true,true).animate({top:'-4px'},200);
    },function(){
        $('span',this).stop(true,true).animate({top:'0px'},400);
    });
});
like image 105
Thorgeir Avatar answered Mar 24 '26 22:03

Thorgeir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!