這很可能只是我的一個沮喪的語法錯誤。但resizeTime只是不清楚。無論多次使用clearInterval,計時器都會繼續運行。任何想法的人?我已經張貼了我真正的代碼:clearInterval無法正常工作
var resizeTime; // declared outside of wrapper function to INSURE no second declaration will occur
var myTransitionEvent = whichTransitionEvent();
$(window).bind('adapt', function(){
console.log('start', resizeTime);
resizeTime = setInterval(function(){
console.log('go', resizeTime);
methods.relayoutChildren.apply(self);
}, 5);
setTimeout(function(){
console.log('sNend', resizeTime);
clearInterval(resizeTime);
},1000);
});
$('#allies-wrap').bind(myTransitionEvent, function(){
console.log('end', resizeTime);
clearInterval(resizeTime);
methods.relayoutChildren.apply(self);
});
下面是鍍鉻的樣本數:
start undefined
start 8215
(10) go 8218
start 8218
start 8221
(256) go 8224
(2) sNend 8224
(9) go 8224
sNend 8224
(3) go 8224
sNend 8224
(2596) go 8224
對於那些誰不知道Chrome的記錄,(2596)指2596次出現相同的日誌。
你有什麼錯誤嗎? – 2012-02-29 15:28:00
沒有錯誤,從我的IDE或瀏覽器;除了在日誌中「走」千次之外。 – Fresheyeball 2012-02-29 15:29:01
我們是否可以有更詳細的運行計時器的代碼示例(在'adapt'綁定中的代碼正在完美地開始並清除間隔http://jsfiddle.net/vHn9r/) – 2012-02-29 15:29:55