Roxana Posted May 25, 2022 Share Posted May 25, 2022 I'm trying to remove a timeline animation below 940px or add it above 940px. I want the animation to be removed or added on resize or when the mobile orientation is changed. Here is my code: const scrollTrigger = { trigger: '.js-hero-pin', start: 0, end: 700, scrub: true, pin: true, pinSpacing: true, anticipatePin: 1, toggleActions: 'play pause reverse pause' } let timeline = gsap.timeline() function timelineAnimation() { if (document.querySelector('.js-hero-video')) { timeline.from('.js-hero-video', { position: 'fixed', top: 0, right: 0, left: 0, width: '100vw', height: '100vh', scrollTrigger: scrollTrigger }) timeline.to('.js-hero-text', { opacity: 0, display: 'none', scrollTrigger: scrollTrigger }) timeline.from('.js-hero-content', { marginTop: '100vh', scrollTrigger: scrollTrigger }) timeline.to('.js-hero-content', { opacity: 1, scrollTrigger: scrollTrigger }) timeline.from('.js-sticky-bar', { display: 'none', zIndex: -1, scrollTrigger: { start: 400, end: 700, scrub: true, toggleActions: 'play pause reverse pause' } }) timeline.to('.js-sticky-bar', { opacity: 1, scrollTrigger: { start: 400, end: 700, scrub: true, toggleActions: 'play pause reverse pause' } }) } } window.addEventListener('load', () => { if (window.innerWidth > 940) { timelineAnimation() } }) window.addEventListener('resize', () => { if (window.innerWidth <= 940) { if (timeline) { ScrollTrigger.disable() } } else { timelineAnimation() ScrollTrigger.enable() } }) When I resize the window or change the mobile orientation, I'd like to remove or add all the animations, with all the CSS properties. Link to comment Share on other sites More sharing options...
Solution elegantseagulls Posted May 25, 2022 Solution Share Posted May 25, 2022 This may be helpful if you are using ScrollTrigger, which it seems you are: https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.matchMedia() 4 Link to comment Share on other sites More sharing options...
Roxana Posted May 26, 2022 Author Share Posted May 26, 2022 Great, thank you so much! 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