Delay between each iteration of foreach loop?

后端 未结 2 874
鱼传尺愫
鱼传尺愫 2020-12-16 20:31

so I am making a simon says game. This function displays the current sequence. The problem with it right now is that it doesn\'t really go in a nice sequence, it kind of doe

2条回答
  •  温柔的废话
    2020-12-16 21:17

    I make use of the jQuery delay function

    Here is a the javascript.

    $(document).ready(function(){
    
      var compSequence = new Array("red", "blue", "yellow");
    
      var displaySequence = function() {
    
          $.each(compSequence, function (i, color) {
            // add delay
            $("#" + color).delay(i * 1000).fadeTo(300, 0).fadeTo(300, 1.0);
          });      
      }
    
      displaySequence();
    
    });
    

    Here is a DEMO

提交回复
热议问题