var speed=20;
        var temp=new Array(); 
        var clipright=document.body.clientWidth/2,clipleft=0 
        for (i=1;i<=2;i++){ 
            temp[i]=eval("document.all.div"+i+".style");
            temp[i].width=document.body.clientWidth/2;
            temp[i].height=document.body.clientHeight;
            temp[i].left=(i-1)*parseInt(temp[i].width);
        } 
        function openit(){ 
            clipright-=speed;
            temp[1].clip="rect(0 "+clipright+" auto 0)";
            clipleft+=speed;
            temp[2].clip="rect(0 auto auto "+clipleft+")";
            if (clipright>0)
                setTimeout("openit()",100);
        }
setTimeout("openit()",10000);试试

解决方案 »

  1.   

    2楼前辈不行啊 ,settimeout是延迟执行只执行一次,我这个 tim=setInterval("openit()",100);是让它100毫秒执行一次,
    但是我这样写,
             function openit(){ 
                clipright-=speed;
                temp[1].clip="rect(0 "+clipright+" auto 0)";
                clipleft+=speed;
                temp[2].clip="rect(0 auto auto "+clipleft+")";
                if (clipright>0)
                    setInterval("openit()",100);
            }
            setTimeout("openit()",10000);
     
     也只是在10秒以后执行了openit()一次,就不接着执行setInterval("openit()",100);了
      

  2.   

    setTimeout放在函数内部 怎么是执行一次
      

  3.   

                if (clipright>0)
                    setTimeout("openit()",100);请看清楚想清楚吧
      

  4.   

    function openit(){ 
                if(t){//然后在这里清楚T}
                clipright-=speed; 
                temp[1].clip="rect(0 "+clipright+" auto 0)"; 
                clipleft+=speed; 
                temp[2].clip="rect(0 auto auto "+clipleft+")"; 
                if (clipright>0) 
                    setInterval("openit()",100); 
            } 
    var t=setTimeout("openit()",10000); 
      

  5.   

    我做了一个例子,基本实现你的想法
    进入页面后5秒后,两个层开始左右缩进
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script>
    var speed=20;
    var temp=new Array(); 
    var clipright;
    var clipleft=0;
    var height;
    var tim;
    function onInit()
    {
    clipright=document.body.clientWidth/2;
    height=document.body.clientHeight;
            for (i=1;i<=2;i++){ 
                temp[i]=eval("document.all.div"+i+".style");
                temp[i].width=document.body.clientWidth/2;
                temp[i].height=height;
                temp[i].pixelLeft=(i-1)*parseInt(temp[i].width);
    temp[i].position = "absolute";// 必须设定绝对定位,否则定位层
            } 
    setTimeout("openit()",5000);// 设定5秒后缩进
    }
         
         function openit()
     { 
              clipright-=speed;
              temp[1].clip="rect(0 "+clipright+" auto 0)";
              clipleft+=speed;
              temp[2].clip="rect(0 auto auto "+clipleft+")";
              if (clipright<=0)
                 clearInterval(tim);
      tim=setInterval("openit()",100);
          } 
    </SCRIPT>
    </head>
    <body onload="onInit()">
    <div id="div1"  style="background-color:#0000CC">div1</div>
    <div id="div2" style="background-color:#00ccCC">div2</div>
    </body>
    </html>