Jump to content
Search Community

Scrolling images in a box

tomg55555 test
Moderator Tag

Go to solution Solved by Toso,

Recommended Posts

Hi there,

It's my first post here I hope I can find some help here since I tried to look everywhere but did not find any solution to my issue.
I'm trying to replicate the effect seen on this website "https://hervebaillargeon.com/", in the section above the landing where when you scroll down some videos are pinned and vertically overlapped. I'm working in a nextjs framework so react based solutions would be awesome but vanilla js it's super fine I'll figure out how to adjust it. As reference I used this codepen:  but what I cannot really understand is how can I implement that in a container which is not scrollable by itself but is content is scrolled and pinned while scrolling the page. Thank you for the help!

See the Pen KKpLdWW by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

Thank you so much for your help Rodrigo, as expected I'm having troubles translating this from JS to NextJs. 

 

I'll show you errors I'm getting:

1st:  

end: () => "+=" + cards.length * cards[0].offsetHeight

 

cards[0].offsetHeight, cards is giving me an error.

 

2nd: 

cards.slice(1).forEach((card, i) => {
    tl.fromTo(card, {
        yPercent: 0

 

again card in the middle line is underlined in red.

 

I suppose the problem is at the beginning when I do create the array but I can't really understand what I'm doing wrong here.

 

 

import React, {useEffect, useRef} from 'react';
import {gsap} from 'gsap'
import {ScrollTrigger} from 'gsap/dist/ScrollTrigger'

const Scroller = () => {

    gsap.registerPlugin(ScrollTrigger);
    const component = useRef(null);
    useEffect(() => {

        let ctx = gsap.context(() => {
            // create as many GSAP animations and/or ScrollTriggers here as you want...

            let cards = gsap.utils.toArray(".card");
            console.log(cards.length);
            console.log(cards[0]);
            let tl = gsap.timeline({
                scrollTrigger: {
                    trigger: ".card-wrapper",
                    pin: ".page-wrapper",
                    start: "top top",
                    scrub: true,
                    markers: true,
                    end: () => "+=" + cards.length * cards[0].offsetHeight
                }
            });

            tl.add(() => {
                console.log("card", 1, "in place")
            }, 0.001);

            cards.slice(1).forEach((card, i) => {
                tl.fromTo(card, {
                    yPercent: 0
                }, {
                    yPercent: -100,
                    duration: 0.5
                });
                tl.add(() => {
                    console.log("card", (i+2), "in place");
                })
            })

            gsap.from("h1", { // <- selector text, scoped to this component!
                opacity: 0,
                y: 100,
                ease: "power3",
                duration: 2
            });
        }, component);

    }, []);

    return (
        <div ref={component}>
            <div className="page-wrapper">
                <div className="wrapper">
                    <div className="card-wrapper">
                        <div className="card card-1">
                            1
                        </div>
                        <div className="card card-2">
                            2
                        </div>
                        <div className="card card-3">
                            3
                        </div>
                        <div className="card card-4">
                            4
                        </div>
                        <div className="card card-5">
                            5
                        </div>
                        <div className="card card-6">
                            6
                        </div>
                    </div>
                </div>
            </div>
        </div>

    );
};
export default Scroller;

 

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 Stackblitz that demonstrates 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 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

 

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: 

 

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

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