This most likely just a frustration syntax error on my part. But resizeTime just won't clear. The timer just keeps going regardless of using clearInterval on it more than once. Any ideas folks? I have posted my real code:
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);
});
Here is a sample log from chrome:
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
for those who don't know chrome's log, (2596) means 2596 occurrences of an identical log.
I think Transition event is not getting triggered but adapt
event gets triggered again and again. So resizeTime
changes before the active one gets cleared.
You can fix it ( at least make it better ) by clearing the interval before setting new one.
clearInterval(resizeTime);
resizeTime = setInterval(function(){
console.log('go', resizeTime);
methods.relayoutChildren.apply(self);
}, 5);
clearTimeout(sNendTime);
sNendTime = setTimeout(function(){
console.log('sNend', resizeTime);
clearInterval(resizeTime);
},1000);
EDIT:
What happens is
adapt
event triggersresizeTime
adapt
event triggersresizeTime
resizeTime
gets overwritten the id to previous interval is lost, but that interval still activeresizeTime
transitionevent
triggers it will only clear the latest intervalFor your code to work there should be a transitionevent
after each adapt
event, but there is not. So we have to clear the active interval and active timeout so that there will be only one of each active at a time, and when timeout ends the function clears interval also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With