我想在运行更多代码之前在.hover()回调函数中添加一个小延迟。我还需要停止计时器,如果它存在,当您悬停另一个触发相同的.hover()函数的元素。 我目前有它的工作,但它不漂亮,我分配一个计时器到全球,并确保有一个更好的方式来做到这一点。在调用函数之前在.hover()回调函数中添加一个延迟
以下是我有:
PACKAGES.activity_icons.hover(function() {
// If a timer exists kill it here becuase we don't want the
// functions in the timer called if we are hovering on another icon
if(typeof image_restore_timer != 'undefined')
{
clearTimeout(image_restore_timer);
}
// Only swap image if icon has a class
if($(this).attr('class') !== '')
{
$(this).closest('.package').find('.left_wrap > img').hide();
// Show the image with the same class as the icon we hovered
$(this).closest('.package').find('.left_wrap img.'+$(this).attr('class')).show();
}
}, function() {
var this_ref = $(this);
// Store timer in a global and restore images after a pause
image_restore_timer = setTimeout(function() {
(function(el) {
el.closest('.package').find('.left_wrap img.'+this_ref.attr('class')).hide();
el.closest('.package').find('.left_wrap > img:eq(0)').fadeIn('slow');
})(this_ref)
}, 1000);
});
太棒了!谢谢 – davewilly 2010-11-14 00:12:07
@davewilly - 欢迎! – 2010-11-14 00:14:52