Howcouleyoubeso
V2EX  ›  jQuery

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

  •  1
     
  •   Howcouleyoubeso · Mar 21, 2016 · 2740 views
    This topic created in 3727 days ago, the information mentioned may be changed or developed.
    新手正在自学 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 replies    2016-03-24 10:24:33 +08:00
    Mirachael
        1
    Mirachael  
       Mar 22, 2016   ❤️ 1
    可以的啊
    Howcouleyoubeso
        2
    Howcouleyoubeso  
    OP
       Mar 22, 2016
    @mojixiang1102 你那里能显示吗 为什么我这不行。。
    Howcouleyoubeso
        4
    Howcouleyoubeso  
    OP
       Mar 23, 2016
    @mojixiang1102 不知道为什么 在 Sublime 编辑后没效果..
    Mirachael
        5
    Mirachael  
       Mar 23, 2016   ❤️ 1
    @Howcouleyoubeso 要引入 jquery 的啊 ,这点不用说吧。
    Howcouleyoubeso
        6
    Howcouleyoubeso  
    OP
       Mar 24, 2016
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1162 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:16 · PVG 07:16 · LAX 16:16 · JFK 19:16
    ♥ Do have faith in what you're doing.