Fork me on GitHub

js文字从左边飞入效果

贴代码之前,我们先讲一下它的原理,我们使用setInterval,让文字一开始置于屏幕看不到的位置,左右上下都可以,然后让它的位置不断移入到屏幕看得到的位置。

下面上代码:

html:

<h2 id="flyin" style="position:relative;left:-400;font-style:italic">
<font face="Arial">陈泽锋教你如何让文字从左边飞入</font>
</h2>

js:

if (document.getElementById||document.all)
var crossheader=document.getElementById? document.getElementById("flyin").style : document.all.flyin.style
function animatein(){
if (parseInt(crossheader.left)<0)
crossheader.left=parseInt(crossheader.left)+20
else{
crossheader.left=0
crossheader.fontStyle="normal"
clearInterval(start)
}
}
if (document.getElementById||document.all)
start=setInterval("animatein()",50)

 

posted @ 2017-08-14 11:54  广东靓仔-啊锋  阅读(5365)  评论(0编辑  收藏  举报