javascript运动功能-分享到

<script>
  //窗体载入,为div控件绑定事件
        window.onload = function () {

            var div1 = document.getElementById('div1');
            //mouseover
            div1.onmouseover = function () {
                startMove(0);
            }
            //mouseout
            div1.onmouseout = function () {

                startMove(-100);
            }
        }
        //定义定时器
        var timer = null;
        //淡入和淡出
        function startMove(targetPoint) {

       
            clearInterval(timer);
            var div1 = document.getElementById('div1');
          
            timer = setInterval(function () {

                var ispeed = 0;
               if (div1.offsetLeft < targetPoint) {

                   ispeed = 10;
               }
               else {

                   ispeed = -10;
               }
                //控件位置
               if (div1.offsetLeft == targetPoint) {
                    clearInterval(timer);
                }
                else {

                    div1.style.left = div1.offsetLeft + ispeed + "px";
                }
            },30);
           
        }
</script>

 

posted on 2015-10-08 16:57  水击三千  阅读(153)  评论(0编辑  收藏  举报

导航