<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
 
<body>
    <div >
        这是一段打字机效果的文字
    </div>
 
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        (function ($) {
            $.fn.typewriter = function () {
                this.each(function () {
                    var $ele = $(this),
                        str = $ele.html(),
                        progress = 0;
                    $ele.html('');
                    var timer = setInterval(function () {
                        var current = str.substr(progress, 1);
                        if (current == '<') {
                            progress = str.indexOf('>', progress) + 1;
                        } else {
                            progress++;
                        }
                        $ele.html(str.substring(0, progress) + (progress & 1 ? '_' : ''));
                        if (progress >= str.length) {
                            clearInterval(timer);
                        }
                    }, 150);
                });
                return this;
            };
        })(jQuery);
 
        $("#pic").show().typewriter(50);
    </script>
</body>
 
</html>

基于jQuery的打字机函数

相关文章:

  • 2021-08-24
  • 2021-11-14
  • 2022-12-23
  • 2021-09-07
  • 2021-07-19
  • 2021-11-25
  • 2021-08-30
猜你喜欢
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-09-24
  • 2022-12-23
相关资源
相似解决方案