devloper Posted June 24 Share Posted June 24 Hello There I want a section to sticky after 2 section on top and in sticky section having 15 inner section which will move one by one on part of section hols text which will hide show as opacity down and up and other part hold image which comes from top right to center and then center to bottom right here is my code but it is not working smooth and curve way <script> gsap.registerPlugin(ScrollTrigger); const locomtvScroll = new LocomotiveScroll({ el: document.querySelector("[data-scroll-container]"), // smooth: true, inertia: 0.8, // Adjusting inertia for smoother scrolling getDirection: true // Optionally track scroll direction }); new ResizeObserver(() => locomtvScroll.update()).observe( document.querySelector("[data-scroll-container]") ); locomtvScroll.on('scroll', (position) => { if ((position.scroll.y) > 5) { document.querySelector('body').classList.add('scrolled'); } else { document.querySelector('body').classList.remove('scrolled'); } }); locomtvScroll.on("scroll", ScrollTrigger.update); ScrollTrigger.scrollerProxy("[data-scroll-container]", { scrollTop(value) { return arguments.length ? locomtvScroll.scrollTo(value, 0, 0) : locomtvScroll.scroll.instance.scroll.y; }, getBoundingClientRect() { return { top: 0, left: 0, width: window.innerWidth, height: window.innerHeight }; }, pinType: document.querySelector("[data-scroll-container]").style.transform ? "transform" : "fixed" }); // Image swap anim gsap.set(".single_rt", { zIndex: (i, target, targets) => targets.length - i, }); gsap.registerPlugin(ScrollTrigger); var images = gsap.utils.toArray(".single_rt"); images.forEach((image, i) => { var tl = gsap.timeline({ scrollTrigger: { trigger: ".product_pin", scroller: "[data-scroll-container]", start: () => "top -" + window.innerHeight * (i + 0.1), end: () => "+=" + window.innerHeight, scrub: 1, toggleActions: "play none reverse none", invalidateOnRefresh: true, }, }); tl.to(image, { duration: 0.5, // Increase duration for slower movement x: "-100%", // Move to center horizontally y: "0%", // Move to center vertically ease: "linear", }) .to(image, { duration: 0.5, // Increase duration for slower movement x: "0", // Move to right from center y: "90%", // Move to center vertically ease: "linear", }) .to(image, { duration: 0.5, // Increase duration for slower movement y: "100%", // Move to bottom right ease: "linear", }); }); // Text swap anim gsap.set(".single_lt", { zIndex: (i, target, targets) => targets.length - i }); var texts = gsap.utils.toArray(".single_lt"); texts.forEach((text, i) => { var tl = gsap.timeline({ scrollTrigger: { trigger: ".product_pin", scroller: "[data-scroll-container]", start: () => "top -" + window.innerHeight * i, end: () => "+=" + window.innerHeight, scrub: true, toggleActions: "play none reverse none", invalidateOnRefresh: true } }); if (i) { tl.to(text, { duration: 0.33, autoAlpha: 1, y: "0%", ease: 'power1.inOut' }); } if (texts[i + 1]) { tl.to(text, { duration: 0.22, autoAlpha: 1, y: "0%", ease: 'power1.inOut' }) tl.to(text, { duration: 0.33, autoAlpha: 0, y: "0%", ease: 'power1.inOut' }, 2); } }); let mb = gsap.matchMedia(); mb.add("(min-width: 1201px)", () => { ScrollTrigger.create({ scroller: "[data-scroll-container]", trigger: ".product_pin", scrub: true, // markers: true, pin: true, start: () => "top", end: () => "+=" + (images.length) * window.innerHeight, invalidateOnRefresh: true, }); }); ScrollTrigger.clearScrollMemory(); window.history.scrollRestoration = "manual"; window.onresize = function (event) { $('.product_pin').css('postion', 'relative') }; </script> Link to comment Share on other sites More sharing options...
GSAP Helper Posted Monday at 11:31 PM Share Posted Monday at 11:31 PM Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: Using a framework/library like React, Vue, Next, etc.? CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: React (please read this article!) Next Svelte Sveltekit Vue Nuxt Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. ✅ 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