首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于setInterval停止后,再次执行有关问题

2013-05-02 
关于setInterval停止后,再次执行问题!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN h

关于setInterval停止后,再次执行问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<div class="xiangmu02" ><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#282828">
<tr>
<td width="0">
    <div id="ddd" style="display:none;">
          <a href="#"><img src='images/06.jpg' border="0"></a>
          <a href="#"><img src='images/07.jpg' border="0"></a>
          <a href="#"><img src='images/08.jpg' border="0"></a>
          <a href="#"><img src='images/09.jpg' border="0"></a>
          <a href="#"><img src='images/10.jpg' border="0"></a>
  </div>
    </td>
    </tr>
    <tr id="td1">
     <td height="88" align="right" width="190" bgcolor="#282828">
      <img id="img1" src="images/01a.jpg" onmouseover="showDaTu('images/06.jpg','#')"/></td>
      <td rowspan="5" valign="top"><a id="defaulta" target="_blank"><img src="images/06.jpg" id="defaultImg" border="0"></a></td>
    </tr>
    <tr>
    <td height="88" align="right"><img id="img2" src="images/02.jpg" onmouseover="showDaTu('images/07.jpg','#')" /></td>
    </tr>
    <tr>
    <td height="88" align="right"><img id="img3" src="images/03.jpg" onmouseover="showDaTu('images/08.jpg','#')" /></td>
    </tr>
    <tr>
    <td height="88" align="right"><img id="img4" src="images/04.jpg" onmouseover="showDaTu('images/09.jpg','#')" /></td>
    </tr>
    <tr>
    <td height="88" align="right"><img id="img5" src="images/05.jpg" onmouseover="showDaTu('images/10.jpg','#')" /></td>
    </tr>

</table>
<script type="text/javascript">
  var index=0;
  var count=document.getElementById("ddd").getElementsByTagName("img").length;
  if(count>0)
  {
  oTimer = setInterval(showDaTuAuto,3000);
  }
  function showDaTuAuto()
  {
  var defaultImg=document.getElementById("defaultImg");
  var defaulta=document.getElementById("defaulta");
  defaultImg.src=document.getElementById("ddd").getElementsByTagName("img").item(index).src;
  defaulta.href=document.getElementById("ddd").getElementsByTagName("a").item(index).href;


  if(++index>=count)
  {
  index=0;
  }
  var aaa ="";
  for (var i=0;i<5;i++){
  if(index == i){
for(var j=1 ; j<=5 ; j++){

aaa = i == j ? "a" : "";
if(i==0 && j ==5) aaa = "a";

document.getElementById("img" + j).src="images/0" + j + aaa + ".jpg"; 
}
}
  }
  }
  
  function start111(){
setInterval(showDaTuAuto,3000);
  }
  function showDaTu(src,href)
  {
  document.getElementById("defaultImg").src=src;
  document.getElementById("defaulta").href=href;
   if (src=="images/06.jpg"){
    document.getElementById("img1").src="images/01a.jpg";
document.getElementById("img2").src="images/02.jpg";
document.getElementById("img3").src="images/03.jpg";
document.getElementById("img4").src="images/04.jpg";
document.getElementById("img5").src="images/05.jpg";

   }
   if (src=="images/07.jpg"){
    document.getElementById("img1").src="images/01.jpg";
document.getElementById("img2").src="images/02a.jpg";
document.getElementById("img3").src="images/03.jpg";
document.getElementById("img4").src="images/04.jpg";
document.getElementById("img5").src="images/05.jpg";

   }
   if (src=="images/08.jpg"){
    document.getElementById("img1").src="images/01.jpg";
document.getElementById("img2").src="images/02.jpg";
document.getElementById("img3").src="images/03a.jpg";
document.getElementById("img4").src="images/04.jpg";
document.getElementById("img5").src="images/05.jpg";

   }
   if (src=="images/09.jpg"){
    document.getElementById("img1").src="images/01.jpg";
document.getElementById("img2").src="images/02.jpg";
document.getElementById("img3").src="images/03.jpg";
document.getElementById("img4").src="images/04a.jpg";
document.getElementById("img5").src="images/05.jpg";

   }
   if (src=="images/10.jpg"){
    document.getElementById("img1").src="images/01.jpg";
document.getElementById("img2").src="images/02.jpg";
document.getElementById("img3").src="images/03.jpg";
document.getElementById("img4").src="images/04.jpg";
document.getElementById("img5").src="images/05a.jpg";

   }
   window.clearInterval(oTimer);
  }

  </script>
</div>
</body>
</html>



当鼠标移动到一张图片上时  setInterval停止 当鼠标移开后怎么让setInterval从停止的地方重新开始
[解决办法]
标记一个当前索引,每次转换图片的时候获取当前索引,然后去定位那张图片。没换一次+1,加到最大值在置为0。
这样只要clearInterval时,要开始的时候直接setinterval

热点排行