为什么我的代码在0那个位置听不下来?

来源:2-1 JS速度动画

慕粉2051358721

2017-04-20 09:01

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>Title</title>
   <style>
#div1{
           width: 200px;
           height: 200px;
           background: yellow;
           position: relative;
           left: -200px;
           top:0;
       }
       #div1 span{
           width: 20px;
           height: 50px;
           background: blue;
           position: absolute;
           left: 200px;
           top: 75px;
       }

   </style>
<script>
window.onload=function () {
   var oDiv=document.getElementById('div1');
   oDiv.onmouseover=function () {
       startMove();
   }
}
   var timer =null;
   function startMove() {
       clearInterval(timer);
       var oDiv=document.getElementById('div1');
       timer=setInterval(function () {
           if(oDiv.offsetLeft==0){
               clearInterval(timer);
           }
           else {
               oDiv.style.left = oDiv.offsetLeft + 1 + 'px';
           }
       },30)
}

</script>

</head>
<body>
<div id="div1"><span id="share">分享</span></div>
</body>

写回答 关注

1回答

  • 慕粉2051358721
    2017-04-20 09:50:08

    在线等  急求!!!

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113931 学习 · 1443 问题

查看课程

相似问题