飘动的文字1
HTML
<p>文字</p>
CSS
p{ position: absolute; left: 10px; top: 0; opacity: 1; }
JS
var oP=document.getElementsByTagName("p")[0]; var timer=null; document.onclick=function(){ timer=setInterval(function(){ var top1=parseInt(getStyle(oP,"top"))+10; var left1=parseInt(getStyle(oP,"left"))+10; var opctiy1=getStyle(oP,"opacity")-0.1; if(opctiy1==0){ clearInterval(timer) } oP.style.top=top1+"px"; oP.style.left=left1+"px"; oP.style.opacity=opctiy1; },30) } function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle(attr); }else{ return getComputedStyle(obj)[attr]; } }