Home > Article > Web Front-end > JS code to achieve automatic typing effect
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='utf-8'> <title>自动打字</title></head><body><p id='auto'></p><script> var str = '这是一段自动打字的代码,很有趣,哈哈哈哈哈哈,呵呵呵呵呵'; var i = 0; function auto(){ var pTyping = document.getElementById('auto'); if (i <= str.length) { pTyping.innerHTML = str.slice(0, i++) ; setTimeout('auto()', 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!