简体   繁体   English

我想在 GSAP 时间线中反转 animation

[英]I wanted to reverse the animation in GSAP timeline

I'm working on GSAP and I wanted to reverse the animation.我正在研究 GSAP,我想扭转 animation。 I used the following approach, but it didn't work.我使用了以下方法,但没有奏效。 Is there any syntactical error?有语法错误吗?

  const svg1 = document.querySelector(".svg1"); 
  window.addEventListener("DOMContentLoaded", () => {
  const tl1 = gsap.timeline({
    onComplete: reverse(),
  });
  const tl2 = gsap.timeline();
  tl1.from(
    svg1,
    { rotate: "0deg,", scale: 1 },
    { rotate: "30deg", scale: 0.8, duration: 2 }
  );
  function reverse() {
    tl2.from(
      svg1,
      { rotate: "30deg,", scale: 0.8 },
      { rotate: "0deg", scale: 1, duration: 2 }
    );
    tl1.play();
  }
});

You have an invalid tween.你有一个无效的补间。 You should either pass in one vars parameter and use .to() or use two vars parameters and use .fromTo() .您应该传入一个 vars 参数并使用 .to( .to()或使用两个 vars 参数并使用.fromTo()

To get it to repeat, just use the repeat and yoyo attributes!要让它重复,只需使用repeatyoyo属性!

const tl1 = gsap.timeline({ repeat: 1, yoyo: true });
tl1.from(".svg1", { rotate: 30, scale: 0.8, duration: 2 });

I highly recommend the GSAP Getting Started article .我强烈推荐GSAP 入门文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM