Javascript setTimeout issue w/ for loop

前端 未结 3 651
天命终不由人
天命终不由人 2021-01-28 02:32

This is my function, when called the related node turns red and then does nothing.
Here is the javascript:

function blink (node, flickers)
{
    originalColo         


        
3条回答
  •  不知归路
    2021-01-28 02:58

    A bit easier to read. http://jsfiddle.net/wUkfe/22/

    function blink(node, flickers){
    
      var color = node.style.color;
    
      (function blinker(){
    
        node.style.color = (flickers % 2) ?  "red" : color;
    
        if (flickers--){
          setTimeout(blinker, 1000);
        }
    
      })();
    
    }
    

提交回复
热议问题