六、TweenMax回调函数

2019-06-12  本文已影响0人  子心_

回调函数:

代码:

<!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-1.8.3.js"></script>
  <script src="js/TweenMax.min.js"></script>
  <style>
    * {
      margin: 0px;
      padding: 0px;
    }
    .wrapper div {
      width: 50px;
      height: 50px;
      margin-bottom: 20px;
      background-color: blue;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <div></div>
    <div></div>
    <div></div>
  </div>
  <button id="btn">按钮</button>
  <script>
    var TweenMax = new TimelineMax() // 必须创建对象
    $("#btn").click(() => {
      TweenMax.staggerTo(".wrapper div", 1, {
        x: 400,
        onStart: function () {
          console.log("运动开始")
        },
        onUpdate: function () {
          console.log("运动中")
        },
        onComplete: function () {
          console.log("运动结束")
          console.log(this.target) // 谁完成就是谁
          this.target.style.background = "red"
        }
      }, 1)
    })
  </script>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读