Fade In String Characters with JQuery?

前端 未结 3 1425
耶瑟儿~
耶瑟儿~ 2021-01-25 18:26

Here is my code. For some reason the entire String fades in at one time instead of each individual character. My console.log shows the characters are being executed one by one.

3条回答
  •  一整个雨季
    2021-01-25 19:03

    The for loop is executing the delay, append and fade in on all letters at once, so they will show at the same time. You want to do this with a setInterval instead:

    var string = "David",
    stringCount = 0;
    
    setInterval(function(){
      $('#fadeIn').append(string[stringCount]);
      stringCount += 1;
    },1000);
    

    Working fiddle: http://jsfiddle.net/bGsa3/

提交回复
热议问题