我需要在鼠标悬停在鼠标上方时闪烁图像并在鼠标悬停后停止闪烁。但是“flash_imgs”总是通过鼠标移动div来调用。while mouse中的Flash图像已结束
如果我使用2个按钮(#start,#stop)和.click() - 一切正常。但我只需要'mouseover'和'mouseout'。
HTML:
<div class="container">
<img src="img1.gif" alt="" class="slide">
<img src="img2.gif" alt="" class="slide">
<img src="img3.gif" alt="" class="slide">
<img src="img4.gif" alt="" class="slide">
</div>
风格:
<style type="text/css">
img { position: absolute; width: 600px; height: 300px;}
div.container { border: 1px solid red; width: 600px; height: 300px; }
</style>
JS:
(function() {
var enable = null,
container = $('div.container'),
imgs = container.find('img'),
timeInOut = 1000,
intervalTime = imgs.length * timeInOut;
imgs.each(function(){
$(this).hide();
});
function flash_imgs(images, time){
images.each(function(i){
$(this).delay(time * i).fadeIn(time/2).fadeOut(time/2);
});
}
container.on('mouseover', function(){
flash_imgs(imgs, timeInOut);
enable = setInterval(flash_imgs, intervalTime, imgs, timeInOut);
});
container.on('mouseout', function(){
clearInterval(enable);
});
})();
谢谢!
*我需要刷新图像*。有一刻[我有一个闪回](http://en.wikipedia.org/wiki/Blink_element)。 – nico 2012-04-06 06:24:55