How to keep animations from repeating JQuery/JavaScript?
I’m creating a drop down nav menu. I want the height to animate down which I have accomplished with a simple JQuery function
$(‘li.brands’).hover(
function(){ $(‘ul’, this).animate({‘height’:’100px’});
$(‘header’).animate({‘height’:'+=100px’});},
function(){$(‘ul’, this).animate({‘height’:’0′});
$(‘header’).animate({‘height’:'-=100px’});}
);
But the problem is when you roll over it multiple times quickly it plays the entire animation over and over. How can I set it so it will start/stop the animation based on how long the person rolls over the link.
Say I want the animation to play for one second, but then someone rolls over the link then rolls off I want to stop the animation before it finishes instead of playing the entire thing.
Any help is appreciated! If further explanation is needed I will edit the post and add more.
- Category: JQuery Questions
I’m creating a drop down nav menu. I want the height to animate down which I have accomplished with a simple JQuery function
$(‘li.brands’).hover(
function(){ $(‘ul’, this).animate({‘height’:’100px’});
$(‘header’).animate({‘height’:'+=100px’});},
function(){$(‘ul’, this).animate({‘height’:’0′});
$(‘header’).animate({‘height’:'-=100px’});}
);
But the problem is when you roll over it multiple times quickly it plays the entire animation over and over. How can I set it so it will start/stop the animation based on how long the person rolls over the link.
Say I want the animation to play for one second, but then someone rolls over the link then rolls off I want to stop the animation before it finishes instead of playing the entire thing.
Any help is appreciated! If further explanation is needed I will edit the post and add more.
Other Questions
Login
Search
Recent Comments
- dgdg_dasdad on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Anas Imtiaz on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- David D on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Wolfman on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- TnT on Having a Jquery PHP problem?


Tom
Posted 10 months ago
So you registered an on hover event, now register an onmouseout event which cancels the current animation and retracts the menu, that’s the gist of it