zoukankan      html  css  js  c++  java
  • 基于jQuery的打字机函数

    <!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 id="pic" style="display: none;">
            这是一段打字机效果的文字
        </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>

  • 相关阅读:
    0808 HTML 基础
    2016.8.3 C#基础 结构体,枚举类型
    2016.8.1 C#基础 传值
    2016.7.22
    2016.7.20
    2016.7.31C#基础 函数
    2016.07.30C#基础 特殊集合
    2016.7.28C#基础 集合
    个人项目网页3
    个人项目网页2
  • 原文地址:https://www.cnblogs.com/ZXH-null/p/13271928.html
Copyright © 2011-2022 走看看