rodgerjr Posted June 20, 2022 Share Posted June 20, 2022 I'm using GSAP to animate things that aren't DOM elements. Specifically a cube in THREE.js. I apologize - I'm not proficient enough to make a minimal demo, but I just want to know if it's possible to pass a class variable from javascript into the ScrollTrigger matchMedia: ScrollTrigger.matchMedia({ "(max-width: 1024px)": () => { this.moveTimeline = new GSAP.timeline({ scrollTrigger: { trigger: ".area-one", start: "top top", end: "bottom bottom", scrub: true, }, }); this.moveTimeline.to(this.cube.position, { x: 5 }); }, }); In this example I have a constructor as such with the variable this.cube: class Cube{ constructor(){ this.cube = three.js cube } } Of course, if I use function(){} I get errors saying "this.cube" is not defined, because I lose the context. But if I use an arrow function I get no errors, but the matchMedia no longer works. Basically nothing moves. Is it possible to access class variables in ScrollTrigger's MatchMedia? Link to comment Share on other sites More sharing options...
Solution rodgerjr Posted June 21, 2022 Author Solution Share Posted June 21, 2022 Woops sorry, arrow functions do work, I just forgot to resize my window lol. 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