jQuery 1.4.2:
我有一个图像。当 mouseover 事件被触发时,会执行一个函数,该函数运行一个循环来加载多个图像。相反, mouseout 事件需要将图像设置回预定图像,并且不再执行循环。这些仅适用于“拇指”类的图像:
$("img.thumb").live("mouseover mouseout", function(event) {
//var foo = $(this).attr('id');
var wait;
var i=0;
var image = document.getElementById(foo);
if (event.type == 'mouseover') {
function incrementimage()
{
i++;
image.src = 'http://example.com/images/file_'+i+'.jpg';
if(i==30) {i=0;}
}
wait = setInterval(incrementimage,500);
} else if (event.type == 'mouseout') {
clearInterval (wait);
image.src = 'http://example.com/images/default.jpg';
}
return false;
});
当我鼠标移出时,图像设置为 default.jpg 但浏览器继续循环浏览图像。它永远不会停止。有人可以用一些知识打我吗?谢谢。