遞歸的理解--無限循環

<!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=utf-8" />
<title>無標題文檔</title>
</head>

<body>
<style type="text/css">
body,div,dl,dd,dt,a,img{ margin:0px; padding:0px;}
img{ border:0 none; vertical-align:top;}
a{ font-size:12px; color:#000; text-decoration:none;}
.main_M_pro{ width:520px; height:auto; margin-top:24px; overflow:hidden; margin:24px auto 0px;}
.main_M_proDl{ width:1000%; overflow:hidden;}
.main_M_pro dl{ float:left; width:133px; height:171px; margin-left: 3px;margin-right: 30px;}
.main_M_pro dt{ width:125px; height:125px; border:#d4d3d3 1px solid;}
.main_M_pro dd{ width:100%; height:44px; line-height:44px; overflow:hidden; text-align:center;}
</style>
<div class="main_M_pro">
    <div class="main_M_proDl" id="box">
        <dl>
            <dt><a href="../product.html"><img src="http://www.baidu.com/img/bdlogo.png" width="125" height="125" alt="1" /></a></dt>
            <dd><a href="../product.html">FDK、FSK系列逆變變壓器</a></dd>
        </dl>
        <dl>
            <dt><a href="../product.html"><img  src="http://picture.youth.cn/qtdb/201508/W020150804262070298525.jpg" width="125" height="125" alt="2" /></a></dt>
            <dd><a href="../product.html">FDK、FSK系列逆變變壓器</a></dd>
        </dl>
        <dl>
            <dt><a href="../product.html"><img src="http://d.youth.cn/qwtf2015/tpy/bjtj/201506/W020150710545179254939.jpg" width="125" height="125" alt="3" /></a></dt>
            <dd><a href="../product.html">FDK、FSK系列逆變變壓器</a></dd>
        </dl>
        <dl>
            <dt><a href="../product.html"><img src="http://d.youth.cn/qwtf2015/tpy/bjtj/201506/W020150609346286302954.jpg" width="125" height="125" alt="3" /></a></dt>
            <dd><a href="../product.html">FDK、FSK系列逆變變壓器</a></dd>
        </dl>
    </div>
</div>



</body>
<script>
    var boxObj=document.getElementById("box");
    var dlObj=boxObj.getElementsByTagName("dl");
    var stop;
    function fun(num)
    {

        num+=2;
        dlObj[0].style.marginLeft=(3-num)+"px";
        if(num<=166)//第一個dl移動的最大距離,即盒子的寬度
        {
            stop=window.setTimeout(function(){fun(num);},50);
        }
        else
        {

            boxObj.appendChild(dlObj[0]);//將第一個dl插到最後
            dlObj[dlObj.length-1].style.marginLeft=3+"px";//將移到最後的dl的marginLeft值設置爲初始值
            fun(0)
        }
    }
    fun(0);//通常設置起始值爲0
    boxObj.onmouseenter=function()
    {
        window.clearTimeout(stop);
    };
    boxObj.onmouseleave=function()
    {
        var num=3-parseInt(dlObj[0].style.marginLeft);//將以前中止時的num值獲得
        fun(num);
    }
</script>
</html>
相關文章
相關標籤/搜索