2012-03-16 91 views
2

我试图阻止跨度的隐藏,而其他跨度淡入其中,但延迟和settimeout似乎没有工作,在鼠标悬停页面上闪烁白色之前其他3图像淡入顶部。延迟在鼠标输出功能上。这里是fiddlejquery延迟和setTimeout

$("#top-left").mouseover(function() { 
     $("#bottom-left").fadeOut(200); 
     $("#bottom-right").fadeOut(200); 
     $("#top-right").fadeOut(200); 
     $(this).css("width","+=400"); 
     $(this).css("height","+=250"); 
     $(this).css("z-index", "-1"); 
    }); 
    $("#top-left").mouseout(function() { 
     $("#bottom-left").fadeIn(200); 
     $("#bottom-right").fadeIn(200); 
     $("#top-right").fadeIn(200).delay(10000); 
     setTimeout(function() { 
       $(this).css("width","-=400"); 
       $(this).css("height","-=250"); 
       $(this).css("z-index", "1"); 
     },400); 
    }); 

谢谢。

回答

2

消防最后一部分作为动画的回调:

$("#top-right").fadeIn(200, function() { 
    $("#top-left").css("width","-=400").css("height","-=250").css("z-index", "1"); 
}); 

这样,它不会执行,直到动画完成。

+1

+1打我!回调函数是JS链式事件的方式。 'settimeout()'也不总是可靠的。 – msanford 2012-03-16 18:23:12

+0

完全没有想到回拨,我会试试看。 – rd42 2012-03-17 13:43:02