Jump to content
Search Community

Scroll trigger horizontal scroll not pinning on top of section in mobile

amanvarshney test
Moderator Tag

Recommended Posts

Pin works fine in desktop but in mobile it over scrolls


i am using nextjs 13 tailwindcss


I read all the other posts on this topic cant figure out what is happening


"use client";
import HomePage from "@/app/home/HomePage";
import {Montserrat} from "next/font/google";
import {ThemeProvider} from "next-themes";
import dynamic from "next/dynamic";

const montserrat = Montserrat({
    subsets: ['latin'],
    display: 'swap',

const About = dynamic(() => import('@/app/about/AboutPage'))
const Contact = dynamic(() => import('@/app/contact/ContactPage'))
const Faqs = dynamic(() => import('@/app/faqs/FaqsPage'))
const Work = dynamic(() => import('@/app/work/WorkPage'))
const Footer = dynamic(() => import('@/app/footer/Footer'))
const Team = dynamic(() => import('@/app/team/TeamPage'))
const GoToTop = dynamic(() => import('@/app/GoToTop'))

export default function Home() {

    return (
        <ThemeProvider attribute="class" defaultTheme={"dark"} disableTransitionOnChange enableSystem={false}>
            <main id="container" className={`text-white ${montserrat.className}`}>
                <GoToTop />
                <Work />
                <Team />
                <Faqs />
                <Contact />
                <Footer />



@tailwind base;
@tailwind components;
@tailwind utilities;

html, body, * {
    @apply p-0 m-0 box-border

body {
    @apply dark:bg-[#121212] bg-[#F2F2F2] overflow-hidden overflow-y-scroll;
    cursor: url('cursor.svg') 15 15, default;

::-webkit-scrollbar {
    width: 10px;
    height: 20px;

::-webkit-scrollbar-track {
    /*@apply dark:bg-[#121212] bg-white*/
    @apply bg-transparent

::-webkit-scrollbar-thumb {
    @apply bg-[#D8E9A8] dark:bg-[#D8E9A8]

::-webkit-scrollbar-thumb:hover {
    background: #4E9F3D;


"use client";
import {gsap} from "gsap";
import {ScrollTrigger} from "gsap/dist/ScrollTrigger";
import {useEffect, useRef} from "react";

export default function Work() {

    const sectionRef = useRef(null);
    const triggerRef = useRef(null);


    useEffect(() => {

        const pin = gsap.fromTo(sectionRef.current, {
            translateX: 0
        }, {
            translateX: "-400vw",
            ease: "none",
            duration: 1,
            scrollTrigger: {
                trigger: triggerRef.current,
                start: "top top",
                end: "2000 top",
                scrub: 0.5,
                pin: true,
                snap: 1 / (5 - 1),

        return () => {

    }, [])

    return (
        <section id="workpage" className={"overflow-hidden"}>
            <div ref={triggerRef}>
                <div ref={sectionRef} className={"h-screen flex flex-row relative w-[500vw]"}>
                    <div className={"h-screen w-full bg-green-800"}></div>
                    <div className={"h-screen w-full bg-blue-200"}></div>
                    <div className={"h-screen w-full bg-red-600"}></div>
                    <div className={"h-screen w-full bg-pink-400"}></div>
                    <div className={"h-screen w-full bg-yellow-200"}></div>

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/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.


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

14 minutes ago, GreenSock said:

Yeah, it's pretty tough to troubleshoot without a minimal demo, but this looked suspicious to me: 

end: "2000 top"

That means "when 2000px down from the top of the trigger element hits the top of the viewport". I wonder if on mobile that's way too far or something. I'm curious why you chose that number. 

i just followed this tutorial


Link to comment
Share on other sites

Sorry, but that tutorial is from a 3rd party, not GreenSock (I've never seen it before). It's not something we can really support here. You'd need to ask the author about what they built there. 


Otherwise, if you've got a GSAP-specific question, please provide a minimal demo (like a CodePen or Stackblitz) with just the minimum amount of code necessary to illustrate the problem and we'd be glad to take a look. Here's a link to a React starter template you can fork: https://stackblitz.com/edit/react-cxv92j

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