下面的代码,是从天滑落一张图片。10秒后收上去。
但我希望,收上去5秒后又再次滑下。10秒后又再次收上去。5秒后再次滑下。如此反复。
请教高手,如何修改。谢谢。<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script type="text/javascript"> 
var intervalId = null; 
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){ 
  this.stayTime=nStayTime*1000 || 3000; 
  this.maxHeigth=nMaxHth || 666; 
  this.minHeigth=nMinHth || 1; 
  this.state=sState || "down" ; 
  var obj = document.getElementById(id); 
  if(intervalId != null)window.clearInterval(intervalId); 
  function openBox(){ 
   var h = obj.offsetHeight; 
   obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px"; 
    if(obj.offsetHeight>this.maxHeigth){ 
    window.clearInterval(intervalId); 
    intervalId=window.setInterval(closeBox,this.stayTime); 
    } 
    if (obj.offsetHeight<this.minHeigth){ 
    window.clearInterval(intervalId); 
    obj.style.display="none"; 
    } 
  } 
  function closeBox(){ 
   slideAd(id,this.stayTime,"up",nMaxHth,nMinHth); 
  } 
  intervalId = window.setInterval(openBox,10); 

</script> 
<div id="MyMoveAd" style="height:6px;overflow:hidden;text-align:center;"> 
<img src=1.jpg>
</div> 
<script type="text/javascript"> 
 <!-- 
 slideAd('MyMoveAd',2); 
--> 
</script> 

解决方案 »

  1.   

    <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script type="text/javascript"> 
    var intervalId = null; 
    function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){ 
    this.stayTime=nStayTime*1000 || 3000; 
    this.maxHeigth=nMaxHth || 666; 
    this.minHeigth=nMinHth || 1; 
    this.state=sState || "down" ; 
    var obj = document.getElementById(id); 
    if(intervalId != null)window.clearInterval(intervalId); 
    function openBox(){ 
    var h = obj.offsetHeight; 
    obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px"; 
    if(obj.offsetHeight>this.maxHeigth){ 
    window.clearInterval(intervalId); 
    intervalId=window.setInterval(closeBox,this.stayTime); 

    if (obj.offsetHeight<this.minHeigth){ 
    window.clearInterval(intervalId); 
    obj.style.display="none"; 
    setTimeout(function() { //<<<<<<<<<<<<<<<<
    obj.style.display=""; 
    slideAd('MyMoveAd',2); 
    }, 5000);


    function closeBox(){ 
     slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);

    intervalId = window.setInterval(openBox,10); 

    </script> 
    <div id="MyMoveAd" style="height:6px;overflow:hidden;text-align:center;"> 
    <img src="http://zi.csdn.net/30060gn.gif">
    </div> 
    <script type="text/javascript"> 
     <!-- 
     slideAd('MyMoveAd',2); 
    --> 
    </script>