“JS setInterval laufen sofort aus” Code-Antworten

JS setInterval laufen sofort aus

function foo() {
   // do stuff
   // ...

   // and schedule a repeat
   setTimeout(foo, delay);
}

// start the cycle
foo();
Naughty Newt

Intervall verwalten für JavaScript

var IntervalManager =
{
 /*  

 set : Set an interval using setInterval and store its ID
  IntervalManager.set( "uniqueID", function reference, milliseconds );    

 clear : Clear an interval and forget its ID
  IntervalManager.clear( "uniqueID" );

 any : Detect if any intervals are active. Returns ID of first active or false.
  if( IntervalManager.any() )
   {...}

 clearAll : Clears all intervals whose IDs are stored and forgets their IDs 
  IntervalManager.clearAll();  

 */

 intervals : [/*28432953637269707465726C61746976652E636F6D*/],

 set : function( intervalID, funcRef, period )
 {
  if( !this.intervals[ intervalID ] )  

   this.intervals[ intervalID ] = setInterval( funcRef, period );
  else
   alert("Attempted to set " + intervalID + ' more than once.');
 },  

 clear : function( id )
 {
  clearInterval( this.intervals[ id ] );  

  delete this.intervals[ id ];  

 },

 clearAll : function()
 {
  var table = this.intervals;  

  for( var i in table )
  {
   clearInterval( table[ i ] );
   delete table[ i ];  

  }      

 },

 any : function()
 {
  var table = this.intervals, found = false;  

  for( var i in table )
   if( table[ i ] !== null )
   {
    found = table[ i ];  

    break;  

   }

  return found;
 }   

}
Mehdi Grn

wie man eine Funktion nach einem festgelegten Intervall JS macht

function sayHi() {
  alert('Hello');
}
//Do a function at a set interval continuously
setTimeout(sayHi, 1000);
//Do a function once after a set interval
setTimeout(sayHi, 1000);
Cruel Chamois

Ähnliche Antworten wie “JS setInterval laufen sofort aus”

Fragen ähnlich wie “JS setInterval laufen sofort aus”

Weitere verwandte Antworten zu “JS setInterval laufen sofort aus” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen