(一)TweenMax的引入和开始移动

2018-09-29  本文已影响0人  我拥抱着我的未来

(1) 本节知识点

(2) 动画运动

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="js/jquery.min.js"></script>
  <script src="js/TweenMax.min.js"></script>
</head>

<body>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    
    #box {
      width: 100px;
      height: 100px;
      background: red;
      position: absolute;
      left: 0px;
      top: 100px;
    }
  </style>
  <div id="box"></div>
  <button id="btn">按钮</button>
</body>
<script>
  $(function() {
    var TweenMax = new TimelineMax(); //必须创建对象
    $("#btn").click(() => {
      TweenMax.to("#box", 2, {
        left: 300,
      },"2") //延迟2秒执行
    })

  })
</script>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="js/jquery.min.js"></script>
  <script src="js/TweenMax.min.js"></script>
</head>

<body>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    
    #box {
      width: 100px;
      height: 100px;
      background: red;
      position: absolute;
      left: 0px;
      top: 100px;
    }
  </style>
  <div id="box"></div>
  <button id="btn">按钮</button>
</body>
<script>
  $(function() {
    var TweenMax = new TimelineMax(); //必须创建对象
    $("#btn").click(() => {
      TweenMax.from("#box", 2, {
        left: 300,
      })
    })

  })
</script>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="js/jquery.min.js"></script>
  <script src="js/TweenMax.min.js"></script>
</head>

<body>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    
    #box {
      width: 100px;
      height: 100px;
      background: red;
      position: absolute;
      left: 0px;
      top: 100px;
    }
  </style>
  <div id="box"></div>
  <button id="btn">按钮</button>
</body>
<script>
  $(function() {
    var TweenMax = new TimelineMax(); //必须创建对象
    $("#btn").click(() => {
     TweenMax.fromTo("#box", 2, {
        left: 100,
      }, {
        left: 400
      })
    })

  })
</script>

</html>
上一篇 下一篇

猜你喜欢

热点阅读