0
我有以下fiddleclearInterval停止懸停動畫jQuery的
當我將鼠標懸停在上一張我希望它移動,因爲它是做什麼,當我停下來徘徊我希望它停止。 請參閱下面的代碼。當我停止懸停但clearInterval不是? 我在這裏做錯了什麼?
<div> <span id="prev">prev</span>
<div class="scroll-container">
<div class="img-container">
<img src="http://dummyimage.com/100x100/000000/fff">
<img src="http://dummyimage.com/100x100/f33636/fff">
<img src="http://dummyimage.com/100x100/0c5b9e/fff">
<img src="http://dummyimage.com/100x100/0c9e0c/fff">
</div>
</div>
</div>
var hoverInterval;
function goLeft() {
if (!$('.img-container').is(':animated')) {
var first = $('.img-container img:first-child');
var firstClone = first.clone();
$('.img-container').append(firstClone);
$('.img-container').animate({
"left": "-=110px"
}, "slow", function() {
first.remove();
$('.img-container').css("left", "0");
});
}
}
$('#prev').hover(
function() {
hoverInterval = setInterval(goLeft, 100);
},
function() {
alert(1);
clearInterval(goLeft);
}
);