JQuery Slideup/Slidedown a div only after previous div animation or after delay
Currently I have a JQuery script in place http://jsfiddle.net/gaby/zzj7E/5/ which handles the requirement that when i hover on a particular div, a hidden div slides down. This happens on every div i hover on.
However you will notice that if one hovers his mouse quickly over the set of divs, it leaves several divs sliding down at once. Actually i dont want this.
What i want is that unless the previous div hasnt fully slided up the other div wont slide down even if hovered on. Or if possible show the div slide down effect only if the user has the mouse hover it for above 1.5 secs.
Is this possible to implemented in jQuery? Can someone help?
EDIT: Had to use .live() to add the effect to dynamically added elements. COuld nt use hover with live() as its proving cumbersome. Below is the code am using
$(".altbgcolor").live('mouseenter', function() {
//hover code
$(this)
.addClass('altbgcolor-active')
.find(".sharedp")
.slideDown('slow');
}).live('mouseleave', function() {
//stopped hovering code
$(this)
.removeClass('altbgcolor-active')
.find("开发者_Python百科.sharedp")
.slideUp('slow');
});
How to integrate the effect in this mouseenter and mouseleave events?
Something like this would work:
http://jsfiddle.net/zzj7E/27/
$(".altbgcolor").hover(function() {
var el= $(this);
el.addClass('altbgcolor-active');
el.data('hover', setTimeout(function()
{
if (el.hasClass('altbgcolor-active'))
{
el.find(".sharedp").slideDown('normal');
}
}, 1500)
);
},function () {
var el= $(this);
clearTimeout(el.data('hover'));
el.removeClass('altbgcolor-active')
.find(".sharedp")
.slideUp('normal');
});
EDIT: if using mouseover and mouseout events instead of hover:
http://jsfiddle.net/zzj7E/30/
$(".altbgcolor").live({
mouseenter: function() {
var el= $(this);
el.addClass('altbgcolor-active');
el.data('hover', setTimeout(function()
{
if (el.hasClass('altbgcolor-active'))
{
el.find(".sharedp").slideDown('normal');
}
}, 1500)
);
},
mouseleave: function () {
var el= $(this);
clearTimeout(el.data('hover'));
el.removeClass('altbgcolor-active')
.find(".sharedp")
.slideUp('normal');
}
});
I'm not 100% sure what you want but i think you are looking for .stop()
there is your updated example: http://jsfiddle.net/zzj7E/18/
精彩评论