JavaScript 高级课程之分享setInterval(),clearInterval(),onmouseover,onmouseout应用(2_自动判断正负)

来源:互联网 发布:怎么下载外国软件 编辑:程序博客网 时间:2024/05/11 18:26
<!doctype html><html><head><meta charset="utf-8"><title>JavaScript 高级课程之分享setInterval(),clearInterval(),onmouseover,onmouseout应用(2_自动判断正负)</title><style>    #div1 { width:100px; height:300px; background-color:#005812; position:absolute; left:-100px;}    #div2 { width:30px; height:100px; position:absolute; background-color:#CBBC5D; right:-30px; top:100px;}</style><script>window.onload = function(){    var oDiv = document.getElementById('div1');    var Timer = null;        oDiv.onmouseover = function(){        fn(0);        };        oDiv.onmouseout = function(){        fn(-100);        };        function fn(value){        if(value < 0){            var si = -10;             }else{                var si = 10;                }            clearInterval(Timer);            Timer = setInterval(function(){                if(oDiv.offsetLeft != value){                    oDiv.style.left = oDiv.offsetLeft + si +'px';                    }else{                        clearInterval(Timer);                        }                },20);        }}</script></head><body><div id="div1">    <div id="div2"></div></div></body></html>

0 0