Search code examples
javascriptfadein

execute a function infinity in javascript


I am trying to fade in a spinner infinity. But spinner will fade out after a time because infinity is not working. My code as follows.

setInterval(function(){
        console.log("fergergerg");
        $("#spinner").fadeIn();
},Infinity);

Where I was wrong and how can I make my spinner to be faded in always?

Simply I needed something like below.

while(true){
   $("#spinner").fadeIn();
}

But it also not working.


Solution

  • The solution is here, the below function executes "load" function every 1000 ms (every 1 sec) for ever and infinite.
    
    function load(){
        $("#spinner").fadeIn();
        setTimeout(load, 1000);
    }; load();
    

    you can change the interval time as you want.