turkey3
turkey3

Reputation: 35

Check Javascript Condition Every Frame

Pretty much, my question is simple, and I did search for a similar question before posting this. I would like to know how to make Javascript code repeatedly execute while the page is open, rather than the code running once and being done or only responding to event handlers. I pretty much want the Javascript equivilant of:

$(document).ready(function() {

});

But I do not want to use Jquery because it is less efficient. I want to check an === condition every single frame.

Upvotes: 0

Views: 8213

Answers (3)

yah yaha
yah yaha

Reputation: 31

requestAnimationFrame(callback)

docs

Upvotes: 0

waelhe
waelhe

Reputation: 381

Use SetInterval .. inside a window.onload function

window.onload = function() {            
     function test() {
         alert("test");
     }
     setInterval(test, time_miliseconds);
 }

Upvotes: 3

jollarvia
jollarvia

Reputation: 379

setInterval(function(){
     var blah = whatever;
     if (done){
         clearInterval();
     }
},time_in_milliseconds);

loop keeps looping per your milliseconds argument. If you want a loop thinner than a millisecond or as hard as the computer can do it then just a regular while(true){} will suffice.

Upvotes: 0

Related Questions