自行引入jquery;(<script src="https://www.jq22.com/jquery/jquery-3.3.1.js"></script>)
<div id="poem" class="poem"></div>
js代码如下:
var flag = 0;
var arr = "十年生死两茫茫,不思量,自难忘。".split('');
for(var i =0;i<arr.length;i++){
$("#poem").append("<span style='opacity:0;'>" + arr[i] + "</span>");
}
var timer = setInterval(()=>{
if(flag == arr.length-1) clearInterval(timer);
$("#poem>span").eq(flag).animate({opacity:1}, 800);
flag++;
},400);