-5
jQuery.noConflict();

jQuery(document).ready(function() {

    // milliseconds
    var intervalTime = 75,

    div = jQuery(".animate"), st = div.text(), timer, count = 0, total = st.length;
    div.html("").css("visibility", "visible");

    timer = setInterval(showLetters, intervalTime);

    function showLetters() {

        if(count < total) {

            div.html(div.text().split("_").join("") + st.charAt(count) + "");
            count++;

        }
        else {

            clearInterval(timer);

        }

    }

});

<div class="animate">Some text here.</div>
4

1 回答 1

3

要“等待”在 Javascript 中做某事,您可以随时使用

setTimeout(callback, intervalInMillis)

因此,如果showLetters()您想等待 3 秒钟,则需要

setTimeout(showLetters(), 3000);

希望有帮助!

于 2013-01-27T04:54:21.610 回答