V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Howcouleyoubeso
V2EX  ›  jQuery

关于网页实现打字机效果的一点问题

  •  1
     
  •   Howcouleyoubeso · 2016-03-21 17:01:10 +08:00 · 2010 次点击
    这是一个创建于 2959 天前的主题,其中的信息可能已经有所发展或是发生改变。
    新手正在自学 js ,想实现打字机效果 但是没成功 请各位看一下 谢谢
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    </head>
    <body>
    <div id="autotype">This is a test</div>
    <script type="text/javascript">
    $.fn.autotype = function() {
    var $tt = $(this);
    var str = $tt.html();
    var index = 0;
    $(this).html('');
    var timer = setInterval(function() {
    var current = str.substr(index, 1);

    if (current == '<')
    index = str.indexOf('>', index) + 1;
    else
    index++;

    $tt.html(str.substring(0, index) + (index & 1 ? '_' : ''));

    if (index >= str.length)
    clearInterval(timer);
    }, 55);
    };

    $("#autotype").autotype();

    </script>
    </body>
    </html>
    6 条回复    2016-03-24 10:24:33 +08:00
    Mirachael
        1
    Mirachael  
       2016-03-22 10:08:45 +08:00   ❤️ 1
    可以的啊
    Howcouleyoubeso
        2
    Howcouleyoubeso  
    OP
       2016-03-22 14:42:52 +08:00
    @mojixiang1102 你那里能显示吗 为什么我这不行。。
    Mirachael
        3
    Mirachael  
       2016-03-23 12:30:45 +08:00   ❤️ 1
    Howcouleyoubeso
        4
    Howcouleyoubeso  
    OP
       2016-03-23 13:20:01 +08:00
    @mojixiang1102 不知道为什么 在 Sublime 编辑后没效果..
    Mirachael
        5
    Mirachael  
       2016-03-23 23:08:10 +08:00   ❤️ 1
    @Howcouleyoubeso 要引入 jquery 的啊 ,这点不用说吧。
    Howcouleyoubeso
        6
    Howcouleyoubeso  
    OP
       2016-03-24 10:24:33 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2530 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:49 · PVG 23:49 · LAX 08:49 · JFK 11:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.