欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)多物體緩沖運(yùn)動(dòng)實(shí)例代碼

 更新時(shí)間:2013年11月29日 16:49:38   作者:  
這篇文章主要介紹了JS實(shí)現(xiàn)多物體緩沖運(yùn)動(dòng)實(shí)例代碼,有需要的朋友可以參考一下

效果:

思路:

利用setInterval計(jì)時(shí)器進(jìn)行運(yùn)動(dòng),offsetWidth實(shí)現(xiàn)寬度的變動(dòng),在用onmouseover將終點(diǎn)和所選中的DIV放入?yún)?shù)再進(jìn)行緩沖運(yùn)動(dòng)。

代碼:

復(fù)制代碼 代碼如下:

<head runat="server">
    <title></title>
    <style type="text/css">
        div
        {
            width: 100px;
            height: 50px;
            background: #0000FF;
            margin: 10px;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var oDiv = document.getElementsByTagName('div');
            for (var i = 0; i < oDiv.length; i++) {
                oDiv[i].timer = null;           //給買個(gè)DIV做個(gè)標(biāo)記,用以關(guān)閉相應(yīng)DIV的定時(shí)器
                oDiv[i].onmouseover = function () {
                    move(this, 400);        //給定時(shí)器輸出參數(shù)
                }
                oDiv[i].onmouseout = function () {
                    move(this, 100);
                }
            }
        };
        function move(div, end) {
            clearInterval(div.timer);
            div.timer = setInterval(function () {
                var speed = (end - div.offsetWidth) / 5;        //(終點(diǎn)-要走的寬度)/縮放系數(shù)=DIV移動(dòng)的速度
                speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);   //小數(shù)取整,也就是進(jìn)位取整
                if (div.offsetWidth == end) {       //當(dāng)?shù)竭_(dá)終點(diǎn)時(shí)關(guān)閉計(jì)時(shí)器
                    clearInterval(div.timer);
                }
                else {
                    div.style.width = div.offsetWidth + speed + 'px';   //移動(dòng)DIV的寬度
                }
            }, 30)
        }
    </script>
</head>
<body>
    <div>
    </div>
    <div>
    </div>
    <div>
    </div>
</body>

相關(guān)文章

最新評(píng)論