前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >javascript运动功能-分享到

javascript运动功能-分享到

作者头像
水击三千
发布2018-02-27 17:36:33
6650
发布2018-02-27 17:36:33
举报
文章被收录于专栏:水击三千水击三千
<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>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-10-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档