麻烦帮我看看,为什么我设置的鼠标滑过一点反应都没有?非常感谢!

来源:2-1 JS速度动画

Sharron

2016-05-30 11:58

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分享</title>
<style type="text/css">
  
  *{
    margin:0;
    padding:0;
  }
  #box{
    width:200px;
    height:122px;
    background:red;
    margin-top:100px;
    padding-top:78px;
    margin-left:-200px;
  }
  #box #share{
    margin-left:200px;
    padding:3px;
    display:block;
    width:20px;
    height:44px;
    background:blue;
    color:white;
    border-radius:3px;

  }

</style>

<script type="text/script">
  window.onload=function(){
    var timer=null;
    var box=document.getElementById("box");
    box.onmouseover=function(){
      startMove();
    }
  }
  function startMove(){
    var box=document.getElementById("box");
    setInterval(function(){
      box.style.margin-left=box.offsetLeft+10+'px';
      },30)
  }

</script>
</head>
<body>
 <div id="box">
  <span id="share">分享</span>
</div>
</body>
</html>


写回答 关注

2回答

  • 飞天意大利面神兽
    2016-05-30 15:07:57
    已采纳

    首先是第34行改成<script type="text/javascript">

    再就是,第45行,那个magin-left在js不是这么用的,而是magrinLeft.

    Sharro...

    感谢您的认真解答!

    2016-05-30 15:18:41

    共 1 条回复 >

  • 树底下的树袋熊
    2016-05-30 15:20:48

    <script type="text/script">改成<script type="text/javascript">

JS动画效果

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

113920 学习 · 1502 问题

查看课程

相似问题