用JavaScript实现动画效果(2)

 1<body>
 2<div id="div1" style="visibility:visible; position:absolute; left:10; top:10; z-index:1;">
 3<table bgcolor="#FFFFCC" border="1" cellpadding="0" cellspacing="0">
 4<tr>
 5<td>I can moving...</td>
 6</tr>
 7</table>
 8</div>
 9<br/><br/>
10<input onclick="startMove()" type="button" value="开始移动"/>
11<input onclick="stopMove()" type="button" value="停止移动"/>
12</body>

这里主要使用了一个叫setTimeout(function, interval)函数,这个函数的参数格式为:
第一个参数“function”为超时后调用的函数名,第二个参数“interval”为超时值,以微秒为单位。

注意一点是如果要停止这个计时器,必须保存调用这个setTimeout()函数后的返回值,通过clearTimeout(id)函数来取消计时器。

Published At
Categories with 网页设计
comments powered by Disqus