打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
基于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>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
php+jquery+ajax+json的一个最简单实例
jquery获取复选框被选中的值
jQuery.param() 例子
html5教程制作简单画板代码分享
jquery动态输入
JS Loading功能的简单实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服