<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div></div>
</body>
<script>
let divEL = document.getElementsByTagName('div')[0]
let text = 'we need love!'
let index = 1
let timer = null
function showText() {
divEL.innerText = text.slice(0, index)
index++
if (index >= text.length) {
clearTimeout(timer)
}
timer = setTimeout(() => showText(), 500)
}
showText()
</script>
</html>
特效一 - - js实现文字一个一个显示
于 2022-08-02 11:13:30 首次发布