试试这个方法:
function Close() {
$(child).each(function() {
window.clearTimeout($(this).data('timerId')); //clear it here
}).css({left:0});
}
$(element).mouseenter(function() {
$(child).each(function(i) {
var timer = window.setTimeout(function() {
$(child).eq(i).stop().animate({left:300});
}, 350 * (i + 1));
$(this).data('timerId', timer); //save timer id here
});
})
$(element).mouseleave(function() {
Close();
});
另请注意,对事件mouseover
不是(这是对mouseout
)。mouseleave
mouseenter
小提琴
这是另一个清除动画的版本(不确定您在寻找什么)
function Close() {
$child.each(function () {
window.clearTimeout($(this).data('timerId')); //clear it here
});
$child.stop(true, true, true).css({left:0}); //clear the queues and reset the position
}
$(element).mouseenter(function () {
$child.each(function (i) {
var timer = window.setTimeout(function () {
$child.eq(i).stop().animate({
left: '300px'
});
}, 350 * (i + 1));
$(this).data('timerId', timer); //save timer id here
});
})
$(element).mouseleave(function () {
Close();
});
小提琴