javascript用什么方法实现图片每隔两秒自动播放?

我要实现最简单的,多幅图片每隔两秒自动滚动,该用什么方法?特别是这个每隔两秒用什么方法控制?

<HTML><HEAD><TITLE></TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META name=keywords content=>
<META name=description 
content=>

<!-reload-!>
<META name=GENERATOR content="MSHTML 8.00.6001.18852"><style type="text/css">

a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
body {
background-color: #F9E9C7;
}
-->
</style>
<script language="JavaScript">
 var img = new Array(4);  // 创建数组
 var nums = 0; 
 if(document.images)
 {
   for(i = 1; i <= 4; i++)
   {
   img[i] = new Image();  // 创建对象实例
   img[i].src = "images/00" + i + ".jpg"; // 设置所有图片的路径及名称
   }
 }
function fort()  // 定义图片切换函数
{
  nums ++;
  document.images[0].src= img[nums].src;
  if(nums == 4)
  nums = 0;
}
function slide()  // 每隔1秒连续不断的调用fort()函数
{
  setInterval("fort()", 1000);
}
</script></HEAD>
<BODY onload=slide()>
<table width="80%" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><p>&nbsp;</p>
    <p><img src="images/001.JPG" alt="" width="892" height="422" align="middle"></p></td>
  </tr>
</table>
<LINK 
rel=stylesheet type=text/css href="images/style.css">
</BODY></HTML>

        你好,你可以看看这里面的script代码,是我自己写的,是一个一秒切换一个图片的效果,你可以将那个1000改成2000即可,希望能帮到你。

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-03-28
每隔两秒用setInterval("function",time) ,用这个函数设置设置一个超时对象
如:setInterval(cycle,time) ;
function cycle() {
//实现方法

}
相似回答