0
嘿傢伙!
我試圖啓動一個計時器,當用戶mouseOver一個元素,並停止在mouseOut。元素是動態創建的,這就是使用活動方法的原因。在jQuery的直播活動中使用setInterval mouseOver/mouseOut
所以我的計時器開始正確,但我無法阻止它!怎麼了?
$elems.live('mouseover mouseout', function(event) {
var self = $(this), i = 0;
if (event.type == 'mouseover') {
var timer = setInterval(function() {
// change the src of the current element for an element of an array of src, much like in a slideshow
self.attr('src', tabSrc[i]);
i === 2 ? i = 0 : i++;
}, 1000);
}
// Handle the mouseOut
else {
// stop the timer <------ when I mouseOut the element, this doesn't seems to work...
clearInterval(timer);
}
});