javascript通過(guò)setInterval()時(shí)間控制來(lái)實(shí)現(xiàn)javascript打字的效果
<html>
<title>打字效果</title>
<body>
<div id ="forasp"></div>
<script language="javascript">
var content = "這里是打出來(lái)的字,網(wǎng)站制作學(xué)習(xí)網(wǎng)專(zhuān)用!";//
var nowi = 0;
function forasp_cn(){//這里是主函數(shù)
if(content.length>nowi)//如果目前長(zhǎng)度大于顯示的字符id則繼續(xù)
{
document.getElementById("forasp").innerHTML += (content.charAt(nowi));
nowi++;
return;
}
else//如果不大于則清除實(shí)踐控制
{clearInterval(f);}
}
f = setInterval("forasp_cn()","100");//每隔100ms調(diào)用一次forasp_cn()函數(shù)
</script>
</body>
</html>
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄