[英]jQuery multiple fade/toggles
I'm trying to setup a small piece of JS and I'm having trouble with the order things take effect. 我正在尝试安装一小段JS,但我无法使订单生效。
When I hover over an image, the details block needs to fade out, then a second block with icon options fade in. 当我将鼠标悬停在图像上时,详细信息块需要淡出,然后淡出带有图标选项的第二个块。
Currently the details block fades out, the options block is toggled on, which is fine. 当前,详细信息块逐渐淡出,选项块已启用,这很好。 However when I mouse off, the fade in for the details block happens before the options is toggled off. 但是,当我关闭鼠标时,将在关闭选项之前进行细节块的淡入。
How do I make the following happen (hover over container > Details fadeout > options toggle on > Mouse off > options toggle off > details fade in)? 如何进行以下操作(将鼠标悬停在容器>详细信息淡出>选项打开>鼠标关闭>选项关闭>详细信息淡入的情况下)?
Here is my current javascript that's almost there. 这是我当前的javascript即将发布的代码。
$j('.category-products li').hover(function(){
var product = $j(this);
product.children('.product-bottom-info').stop().fadeToggle(700, function(){
if(product.find('.catalog-image-container').length){
//this is a multi image product
product.find('.image-bottom-controlls').stop().toggle();
}
});
});
---- Update ---- ----更新----
You are only passing .hover 1 parameter, so this happens when the li is entered AND left. 您仅传递.hover 1参数,因此在输入li并离开时会发生这种情况。 You can pass hover 2 functions, mouseIn and mouseOut. 您可以传递悬停2个函数mouseIn和mouseOut。
So try: 因此,请尝试:
$j('.category-products li').hover(function(){
var product = $j(this);
product.children('.product-bottom-info').stop().fadeToggle(700, function(){
if(product.find('.catalog-image-container').length){
//this is a multi image product
product.find('.image-bottom-controlls').stop().toggle();
}
});
}, function() {
var product = $j(this);
product.children('.image-bottom-controlls').stop().fadeToggle(700, function(){
if(product.find('.catalog-image-container').length){
product.find('.product-bottom-info').stop().toggle();
}
});
);
Try putting product.find('.image-bottom-controlls').stop().toggle();
尝试将product.find('.image-bottom-controlls').stop().toggle();
in the callback on the fadeToggle. 在fadeToggle的回调中。 This way it always happens after the fadeToggle listener finishes. 这样,它总是在fadeToggle侦听器完成之后发生。
Ref: http://api.jquery.com/fadeToggle/ 参考: http : //api.jquery.com/fadeToggle/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.