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

JS code to achieve automatic typing effect

小云云
Release: 2018-03-26 16:14:24
Original
3520 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template