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)專用!;//
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>