M.O.S. Studios Posted September 20, 2010 Share Posted September 20, 2010 Hey guys, Basically i wanted to make a function that is like setInterval but can have the interval change. this is what i've got so far. window.setVariableInterval = function(callbackFunc, timing){ var variableInterval = { firstInterval: timing, interval: timing, callback: callbackFunc, clear: "", placeHolder: function(){return variableInterval.clear = setInterval( function(){ if(variableInterval.interval == variableInterval.firstInterval){ variableInterval.callback.call(variableInterval); }else{ clearInterval(variableInterval.clear); this.placeHolder(); } }, variableInterval.interval) } } return variableInterval.placeHolder(); }; var that = setVariableInterval(function(){this.interval++; document.getElementById('test').innerHTML = this.interval+ " - " +this.firstInterval}, 1); the following example shows a script that continuously counts up, and slows down by 1 millisecond each time. So far I have it working fairly well. Interval keeps going, and stops when the interval changes. my problem occurs when I try and get it to restart at the new interval rate. that process happens in between the asters. thanks in advance Link to comment https://forums.phpfreaks.com/topic/213933-variable-setinterval/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.