Show text letter by letter

前端 未结 16 1530
旧巷少年郎
旧巷少年郎 2020-11-27 16:38

What is the most elegant way of showing an html text letter by letter (like videogame captions) using CSS and JavaScript?

While I\'m sure that his can be solved usin

16条回答
  •  佛祖请我去吃肉
    2020-11-27 17:08

    HTML

    Javascript

    var showText = function (target, message, index, interval) {   
      if (index < message.length) {
        $(target).append(message[index++]);
        setTimeout(function () { showText(target, message, index, interval); }, interval);
      }
    }
    

    Call with:

    $(function () {
      showText("#msg", "Hello, World!", 0, 500);   
    });
    

提交回复
热议问题