Jump to content
Search Community

smooth gsap easing in the start and at the end but not in between

nicmare test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

the timescale example is what i was looking for. in the start there is smooth easing, in the middle(during hover) an infinite loop and at the end it kinds of fades out with easing. thanks @OSUblake – but i like the code more of @cassie 2nd codepen as i need to be sure to trigger animation for the current element if there are multiple with same classes at once. so this is my final code:

$(".btn-rotated").mouseover((e) => {
    gsap.to(e.currentTarget, {
      duration: 5,
      ease: "none",
      rotation: "-=360deg",
      repeat: -1
    });
}).mouseleave((e) => {
    gsap.to(e.currentTarget, {
      duration: 2,
      ease: "power.out",
      rotation: "-=50deg",
      overwrite: true
    });
});

only thing whats missing is the smooth easing start. 

Link to comment
Share on other sites

  • Solution
9 minutes ago, nicmare said:

but i like the code more of @cassie 2nd codepen as i need to be sure to trigger animation for the current element if there are multiple with same classes at once.

 

Yeah, that's what loops are for. 😉

 

gsap.utils.toArray(".btn-rotated").forEach(btn => {
  
  const animation = gsap.to(btn, {
    paused: true,
    rotation: 360,
    repeat: -1,
    ease: "none",
    duration: 5
  }).timeScale(0);
  
  btn.addEventListener("mouseenter", () => {
    animation.play();
    gsap.to(animation, {
      timeScale: 1,
      duration: 1,
      overwrite: true
    });
  });
  
  btn.addEventListener("mouseleave", () => {
    gsap.to(animation, {
      timeScale: 0,
      duration: 1,
      overwrite: true,
      onComplete() {
        animation.pause();
      }
    });
  });
});

 

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...