clearInterval在Firefox中不起作用
clearInterval does not work in Firefox
我认为这是一些神奇的东西,这在Chrome中工作得很好,但在Firefox或Opera中却不行
var initList = setInterval(function(){
if( cache.isAnimating ) return false;
cache.isAnimating = true;
aux.navigate( 1, $el, $wrapper, settings, cache ); //slide
}, 3500) ;
$(document).ready(function(){
initList = setInterval(function(){
if( cache.isAnimating ) return false;
cache.isAnimating = true;
aux.navigate( 1, $el, $wrapper, settings, cache );
}, 3500) ;
})
鼠标悬停时Firefox没有clearInterval:
$("div.ca-wrapper").mouseover(function(){
clearInterval(initList);
}).mouseout(function(){
initList = setInterval(function(){
if( cache.isAnimating ) return false;
cache.isAnimating = true;
aux.navigate( 1, $el, $wrapper, settings, cache );
}, 3500) ;
})
有什么建议吗?
你不应该重复声明相同的变量(initList)两次。为每个间隔使用唯一的名称。
也许,这就是你要找的:
var initList2, initList1 = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache); //slide
}, 3500);
$(document).ready(function () {
initList2 = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache);
}, 3500);
})
$("div.ca-wrapper").mouseover(function () {
clearInterval(initList1);
clearInterval(initList2);
}).mouseout(function () {
initList2 = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache);
}, 3500);
})
但是使用您的原始代码,作为setInterval返回一个整数,您也可以使用这个:
不要用
引用Boris Zbarsky
不能保证setInterval返回连续整数(事实上在某些情况下它并没有),所以"减一"方法并不是那么好…
var initList = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache); //slide
}, 3500);
$(document).ready(function () {
initList = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache);
}, 3500);
})
$("div.ca-wrapper").mouseover(function () {
clearInterval(initList);
clearInterval(initList - 1); // HERE, we are clearing the previous interval
}).mouseout(function () {
initList = setInterval(function () {
if (cache.isAnimating) return false;
cache.isAnimating = true;
aux.navigate(1, $el, $wrapper, settings, cache);
}, 3500);
})
我认为ready
之前的setInterval
调用是不需要的
function doSomething(){
if( cache.isAnimating ) return false;
cache.isAnimating = true;
aux.navigate( 1, $el, $wrapper, settings, cache );
}
$(document).ready(function(){
initList = setInterval(doSomething, 3500) ;
});
$("div.ca-wrapper").mouseenter(function(){
clearInterval(initList);
}).mouseleave(function(){
initList = setInterval(doSomething, 3500) ;
})
是否尝试删除第一个setInterval?此外,我已经把你的代码干了一点。
$(document).ready(function(){
var initList = null;
setInit();
$("div.ca-wrapper").mouseover(function(){
clearInterval(initList);
}).mouseout(function(){
setInit();
});
})
function setInit() {
initList = setInterval(function(){
if( cache.isAnimating ) return false;
cache.isAnimating = true;
aux.navigate( 1, $el, $wrapper, settings, cache );
}, 3500);
}
相关文章:
- 为什么javascript:void(0)在Firefox中不起作用
- jpm的默认Firefox路径没有'不起作用
- 设置 CSS 背景在 Firefox 中不起作用
- document.getElementById 在 Firefox 中不起作用
- firefox中的CSS动画不起作用
- event.stopPropagation()在firefox javascript中不起作用
- 复选框.onClick在firefox中不起作用
- window.close();在Chrome和Firefox中不起作用
- JQuery在Chrome中不起作用,但Firefox很好
- 选择“行在 Chrome 和 Firefox 中不起作用(生成的代码)”
- Javascript 按键事件在 Firefox 中不起作用
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 更改 Angular 2 中选择的事件在 Firefox 和 Edge 中不起作用
- jQuery SlideToggle() 在 FireFox 中不起作用,在 Chrome 中工作
- 动态关键帧插入在 IE 或 Firefox 上不起作用
- 使用 nameProp 的 JQuery 图像滚动更新在 Firefox 和 Chrome 中不起作用
- Javascript键码在Firefox中不起作用,但在chrome中运行良好
- HTML5<视频>元素在Firefox、Opera和Safari中不起作用
- 输入类型的图像在Internet Explorer中不起作用,但在Chrome和Firefox中起作用
- Ajax 提交表单不起作用 Firefox