Jump to content
Search Community

Unusual behavior in the mouse movement

DemonDisguise
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Rodrigo
Posted

Hi,

 

We can't reach the URL you posted:

V0AkMOI.pngPlease share the URL for the editor, not the project preview.

 

Finally GSAP has type definitions:

https://github.com/greensock/GSAP/tree/master/types

 

We haven't received any complain from developers about GSAP being hard to use with typescript, my guess is that you could be missing the definitions.

  • Solution
Rodrigo
Posted

Hi,

8 hours ago, DemonDisguise said:

And you are right i am bad at types and all.

Yeah, typescript is really not my jam at all and I don't use it unless I have to 🫠, so I completely understand.

 

Is worth noticing that there is a concept error in your code here:

const { context, contextSafe } = useGSAP(
  () => {
    (xTo.current = gsap.quickTo(boxRef.current, 'x', {
      duration: 0.8,
      ease: 'power3',
    })),
      (yTo.current = gsap.quickTo(boxRef.current, 'y', {
      duration: 0.8,
      ease: 'power3',
    }));
  },
  { scope: app }
);

Basically you have a couple of definitions for some refs, but there is no need to add the parenthesis around, also no reason for that comma between them. Those are not properties or keys inside an object, there are assignments inside the scope of a function, nothing more. This is more clear:

const { context, contextSafe } = useGSAP(
  () => {
    xTo.current = gsap.quickTo(boxRef.current, 'x', {
      duration: 0.8,
      ease: 'power3',
    });
    yTo.current = gsap.quickTo(boxRef.current, 'y', {
      duration: 0.8,
      ease: 'power3',
    });
  },
  { scope: app }
);

Also in your definitions you can use this:

const xTo = useRef<gsap.QuickToFunc|any>(null);
const yTo = useRef<gsap.QuickToFunc|any>(null);

Perhaps you're trying to achieve this:

https://stackblitz.com/edit/stackblitz-starters-1l1mlbqx?file=app%2Fglobals.css,app%2Fpage.tsx

 

Hopefully this helps

Happy Tweening!

DemonDisguise
Posted

well it works thanks a lot for helping me with the dumbest questions i have. Just one more doubt ( well I dont know if it is related to gsap or not) but the code works differently in my vs code dev compared to stackblitz why is that like I had to add all of this code        

	    const bounds = app.current.getBoundingClientRect();

        const flairBounds = flairRef.current.getBoundingClientRect();



        const x = e.clientX - bounds.left - flairBounds.width / 2;

        const y = e.clientY - bounds.top - flairBounds.height / 2;



        xTo.current(x);

        yTo.current(y);

 in place of your code to make it work like how it was working in stackblitz. So, I think what will the user see when i launch the website and like what is a good practise here? (Well I am bad at asking question as well, hope you understand what I am trying to ask). 

Rodrigo
Posted

Honestly I couldn't really tell you, I've tested on my local machine the code of this demo:

See the Pen Rwvdowy by GreenSock (@GreenSock) on CodePen.

 

In development and production mode without any need to add that particular code you're mentioning. Maybe this has to do with some peculiarity on your HTML layout, but I'm just guessing here 🤷‍♂️

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...