Jump to content
Search Community

Translate being applied wrong

AniMartin test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi you lovely animators!

 

I have an odd issue I would be grateful to get your thoughts on.

 

I have a background image that moves when the mouse moves over it. This is for a listing page where the item cards have this bg image that move on hover.

 

The issue is they all work fine apart from a couple that doesn't apply the correct translate.

 

So each bg image is set in css to

transform: translate(-50%, -50%);

 

Then GASP applies a 3d transform which works by setting a style attribute as follows:

transform: translate(-50%, -50%) translate3d(-27.4375px, 10.8641px, 0px);

 

Great! That works and respects the css style, but the couple that don't work are applying:

transform: translate(-50%, 0%) translate3d(6.9688px, 5.4241px, 0px);

 

 

So the Y translate is being ignored an reset to 0 :(

 

I have tried updating the GSAP package to the latest version but no luck.

 

I can't seem to figure this one out, any thoughts?

 

Is it possible to force GSAP to add the translate at the same time as the 3d translate?

 

My current code:

gsap.to(bgImage, {
                x: ((e.clientX - card.offsetWidth / 2) / card.offsetWidth) * movement,
                y: ((e.clientY - card.offsetHeight / 2) / card.offsetHeight) * movement,
                duration: 0.5,
                ease: "Power4.inOut",
                force3D: true,
            });

 

Sorry, I can't afford the time at work to create a CodePen.

 

Thanks.

 

 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

  • Like 1
Link to comment
Share on other sites

  • Solution

It's beter to let GSAP handle all the transforms and translates. It seems with transform: translate(-50%, -50%); you want to center stuff, there are more ways to center things now with Flexbox and Grid, so that is a way to go.

 

Or what I sometimes do is wrap my element in an extra div and let GSAP do it's magic on that other div and don't give it one that already has transforms on it. 

 

But please include a demo next time with your issue, now we're just guessing the issue instead of seeing it. 

  • Like 2
Link to comment
Share on other sites

Thanks so much for your help.

 

I would normally take the time to knock out a CodePen but my deadline is tomorrow morning and I simply can't.

 

I will see what I can do once I smash my priorities task list.

 

Mvaneijgen, You might be onto something. Maybe I can centre it another way!

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