Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.