Fade In String Characters with JQuery?

前端 未结 3 1389
耶瑟儿~
耶瑟儿~ 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 18:53

    To get the individual letters to fade in, they need to be DOM elements.

    $(function() {
      var string = " David";
      var q = jQuery.map(string.split(''), function (letter) {
        return $(''+letter+'');
      });
    
      var dest = $('#fadeIn');
    
      var c = 0;
      var i = setInterval(function () {
        q[c].appendTo(dest).hide().fadeIn(1000);
        c += 1;
        if (c >= q.length) clearInterval(i);
      }, 1000);
    
    });
    

    http://jsfiddle.net/bGsa3/5/

提交回复
热议问题