日期:2014-05-16  浏览次数:20346 次

会跳动的文字


<script   languae= "JavaScript ">
 
function   movetext()
{

c1=Math.floor(Math.random()*256);
c2=Math.floor(Math.random()*256);
c3=Math.floor(Math.random()*256);

document.all.a1.style.fontSize=16+Math.floor(Math.random()*24);   //改变字大小
document.all.a1.style.lineHeight=1.2;   //行高取文字的1.2倍。
document.all.a1.style.color= "rgb( "+c1+ ", "+c2+ ", "+c3+ ") ";   //改变文字的颜色。
document.all.a2.style.fontSize=16+Math.floor(Math.random()*24);
document.all.a2.style.lineHeight=1.2;
document.all.a2.style.color= "rgb( "+c2+ ", "+c1+ ", "+c3+ ") ";
document.all.a3.style.fontSize=16+Math.floor(Math.random()*24);
document.all.a3.style.lineHeight=1.2;
document.all.a3.style.color= "rgb( "+c3+ ", "+c2+ ", "+c1+ ") ";
document.all.a4.style.fontSize=16+Math.floor(Math.random()*24);
document.all.a4.style.lineHeight=1.2;
document.all.a4.style.color= "rgb( "+c2+ ", "+c3+ ", "+c1+ ") ";
document.all.a5.style.fontSize=16+Math.floor(Math.random()*24);
document.all.a5.style.lineHeight=1.2;
document.all.a5.style.color= "rgb( "+c1+ ", "+c3+ ", "+c2+ ") ";
document.all.a6.style.fontSize=16+Math.floor(Math.random()*24);
document.all.a6.style.lineHeight=1.2;
document.all.a6.style.color= "rgb( "+c3+ ", "+c2+ ", "+c1+ ") ";

setTimeout( "movetext() ",300);   //每300毫秒刷新一次。
}
 
</script>

<body   onload= "movetext() ">

<table   width= "90% "   height= "60 "   border= "0 "   >
<tr   >           <!--span的存在纯粹是应用样式,span换成div也可以-->
<td> <span   id= "a1 "> 赛 </span> </td>  
<td> <span   id= "a2 "> 迪 </span> </td>
<td> <span   id= "a3 "> 互 </span> </td>
<td> <span   id= "a4 "> 动 </span> </td>
<td> <span   id= "a5 "> 学 </span> </td>
<td> <span   id= "a6 "> 校 </span> </td>
</tr>
</table>  


</body>

这是我的一段代码,运行后很好看,文字可以跳动,变色,变大小。我不明白的是文字为什么可以左右移动,这段代码好像没有哪一句让它左右移动吧

------解决方案--------------------
document.all.a1.style.fontSize=16+Math.floor(Math.random()*24); //改变字大小
因为你的 <td width= "150 "> <span id= "a1 "> 赛 </span> </td> 是放在表格里的,字体变大了
格子也会变大,字体变小了格子也会变小,所以字会左右的动