AniMartin Posted September 7, 2022 Share Posted September 7, 2022 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 More sharing options...
GSAP Helper Posted September 7, 2022 Share Posted September 7, 2022 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. 1 Link to comment Share on other sites More sharing options...
Solution mvaneijgen Posted September 7, 2022 Solution Share Posted September 7, 2022 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. 2 Link to comment Share on other sites More sharing options...
AniMartin Posted September 7, 2022 Author Share Posted September 7, 2022 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 More sharing options...
AniMartin Posted September 7, 2022 Author Share Posted September 7, 2022 Centering another way sorted my issue! Many thanks all, and in particular thanks Mvaneijgen! I think I will try to recreate the issue in a Codepen at some point for my own sanity and to share the issue. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now