Home  >  Article  >  Web Front-end  >  JS code to achieve automatic typing effect

JS code to achieve automatic typing effect

小云云
小云云Original
2018-03-26 16:14:243488browse

This article mainly shares with you JS to achieve automatic typing effect. It is mainly shared with you in the form of code. I hope it can help everyone.

<!DOCTYPE html><html><head>
    <meta charset=&#39;utf-8&#39;>
    <title>自动打字</title></head><body><p id=&#39;auto&#39;></p><script>
    var str = &#39;这是一段自动打字的代码,很有趣,哈哈哈哈哈哈,呵呵呵呵呵&#39;;    var i = 0;    function auto(){
        var pTyping = document.getElementById(&#39;auto&#39;);        if (i <= str.length) {
            pTyping.innerHTML = str.slice(0, i++) ;
            setTimeout(&#39;auto()&#39;, 150);//递归调用
        }
    }
    auto();</script></body></html>

The above is the detailed content of JS code to achieve automatic typing effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn