Friday, March 18, 2016

jQuery display character text one by one

<div id="mydiv"></div>
<button>Go</button>

<script>
var mystr = 'How are you doing?';

$(document).ready(function() {
    $('button').click(function() {
        var dv = $('#mydiv');
        dv.text("");

        jQuery({
            count: 0
        }).animate({
            count: mystr.length
        }, {
            duration: 4500,
            step: function() {
                dv.text(mystr.substring(0, Math.round(this.count)));
            },
        });
    });
});
</script>

No comments: