Simulate scrolling text in javascript

前端 未结 5 1429
清酒与你
清酒与你 2021-01-16 20:52

I\'m trying to come up with something to simulate an old school modem connection. I.E. text that paints itself at variable speeds rather than rendering at once.

Her

5条回答
  •  悲哀的现实
    2021-01-16 21:11

    Alternative way

    var txt="Lorem ipsum dolor sit amet";
    index=0;
    function displayText(text) {
        $('#test').append(text[index]); index ++;
        $('#test').append(text[index]); index ++;
        if (index  < text.length) {
            setTimeout(function(){ displayText(txt) }, 1);
        }
    }
    
    displayText(txt);
    

    DEMO.

    Or using a closer

    function txt_show(text)
    {
        var index=0;
        var txt=text;
        displayText();
        function displayText() {
            $('#test').append(txt[index]); index ++;
            $('#test').append(txt[index]); index ++;
            if (index  < txt.length) setTimeout(displayText, 1);
        }
    }
    var txt="Lorem ipsum dolor sit amet";
    txt_show(txt);
    

    DEMO.

    But in IE it'll be slower (Only tested in IE8, FF and Chrome).

提交回复
热议问题