Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I unable to prevent the animation queue from stacking without breaking my code?

I am attempting to use jquery and CSS to animate the buttons of a navigation sidebar I am using to signify which button is selected when the mouse is hovered over each.

Currently, my code for the CSS appears as such:

#navbutton {position:relative; width:178px; height:35px; border:1px #FFF solid; z-index:+3; font-family:'Capriola', sans-serif; font-size:18px; text-align:center;}

#navbutton.button {color:#77D; background-color: #F0B0D0;}
#navbutton.button_hover {color:#66C; background-color: #FCF; padding:10px;}

And my jquery:

<script type="text/javascript">
$(document).ready(function(){

$("#sidebar div").mouseenter(buttonHover) 

function buttonHover(){
    $(this).stop().switchClass('button','button_hover',500);
    }

$("#sidebar div").mouseleave(button)

function button(){
    $(this).stop().switchClass('button_hover','button',500);
    }   

});
</script>

Before I added the .stop() to each part of the animation, the animation queue would stack up for each time the mouse was moved over each button and then removed. Now that the .stop() has been applied, however, if the mouse is moved away from a button during its animation, the button will freeze and remain in its mid-animation state, unable to be fixed by being hovered over until the page is reloaded, rather than reverting to its original mouseleave state.

From everything I've read, this should not be the case. Might anyone be able to tell why my animation queue becomes broken once the .stop() is applied?

like image 606
user1888886 Avatar asked Dec 30 '25 17:12

user1888886


1 Answers

Use .stop(true,true) to make it go to the end of the current animation, otherwise it will just stop wherever it is.

http://api.jquery.com/stop/

like image 129
Kevin B Avatar answered Jan 01 '26 08:01

Kevin B



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!