user27731492
user27731492

Reputation:

vertical scrolling inside of horizontal scrolling in gsap

I have to create a website where the content is horizontally scrolled. In the content i different panel and for one of them i should be able to scroll vertically before starting again horizontally scrolling.

I found an example of what it should look like here : on the products part ("days comfy) example

I know its quite bad user experience but still i need to do it.

I cant seem to find a way to fixed the vertically content correctly so the vertically scroll start before its fully on the screen and it ends before the vertically content is all seen.

I would like to horizontally scroll to project div, then when its fully on the screen, it gets fixed and i can vertically scroll the dynamic content. Then when i've scrolled through all of dynamic content. The project is unfixed and i can start scrolling horizontally again.

Thank you for your help, anything help!

my HTML code for now :

<div class="container">
<div class="block"></div>
<div class="block project">
  <div class="project__wrapper">
    <div class="project-content --content1">
      <h3>Projects</h3>
    </div>
    <div class="project__dynamic-wrapper">
      <div class="project__dynamic">
        <div class="project-content --content2">
          <div class="project-slider">
            <div class="project-slider__bg"></div>
            <div class="project-slider__deco"></div>
            <a href="" class="project-slider__link">
              <img src="https://placehold.jp/30/dd6699/ffffff/300x150.png?text=placeholder+image" alt="">
            </a>
          </div>
        </div>

        <div class="project-content --content3">
          <div class="project-info">
            <div class="project-info__number">
              <p class="label">No.</p>
              <p class="now">1</p>
              <p class="all">{all}</p>
            </div>
            <h2 class="project-info__title">1</h2>
            <p class="project-info__subtitle">eee</p>
            <p class="project-info__desc">fff</p>
            <a href="{link}" class="button">Button</a>
          </div>
        </div>
      </div>
      <div class="project__dynamic">
        <div class="project-content --content2">
          <div class="project-slider">
            <div class="project-slider__bg"></div>
            <div class="project-slider__deco"></div>
            <a href="" class="project-slider__link">
              <img src="https://placehold.jp/30/dd6699/ffffff/300x150.png?text=placeholder+image" alt="">
            </a>
          </div>
        </div>

        <div class="project-content --content3">
          <div class="project-info">
            <div class="project-info__number">
              <p class="label">No.</p>
              <p class="now">2</p>
              <p class="all">{all}</p>
            </div>
            <h2 class="project-info__title">2</h2>
            <p class="project-info__subtitle">eee</p>
            <p class="project-info__desc">fff</p>
            <a href="{link}" class="button">Button</a>
          </div>
        </div>
      </div>
      <div class="project__dynamic">
        <div class="project-content --content2">
          <div class="project-slider">
            <div class="project-slider__bg"></div>
            <div class="project-slider__deco"></div>
            <a href="" class="project-slider__link">
              <img src="https://placehold.jp/30/dd6699/ffffff/300x150.png?text=placeholder+image" alt="">
            </a>
          </div>
        </div>

        <div class="project-content --content3">
          <div class="project-info">
            <div class="project-info__number">
              <p class="label">No.</p>
              <p class="now">3</p>
              <p class="all">{all}</p>
            </div>
            <h2 class="project-info__title">3</h2>
            <p class="project-info__subtitle">eee</p>
            <p class="project-info__desc">fff</p>
            <a href="{link}" class="button">Button</a>
          </div>
        </div>
      </div>
    </div>

  </div>
  </div>
<div class="block"></div>
</div>

my scss :

body {
  overscroll-behavior: none;
  height: 100vh;
}
.container {
  width: 400%;
  overscroll-behavior: none;
  height: 100vh;
  display: flex;
  flex-wrap: nowrap;
}
.block {
  width: 100vw;
  height: 100vh;
  background: bisque;
}

// PROJECT

.project {
  width: 100vw;
  height: 100vh;
  background: red;
  //overflow: hidden;
  
  &__wrapper{
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
  }

  &__dynamic-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    background: white;
    width: 56vw;
    height: 100%;
  }

  &__dynamic {
    display: flex;
    flex-wrap: wrap;
    height: 80vh;
  }
  
}

.project-content {
  &.--content1 {
    
    font-size: 100px;
    font-weight: bold;
  }

  &.--content2 {
    position: relative;
    width: 50%;
    height: 28vw;
  }

  &.--content3 {
    width: 50%;
    text-align: right;
  }
}

.project-slider {
  display: flex;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 2vw;
  background-color: cadetblue;
}

.project-info {
  background-color: cadetblue;
}


and my js/gsap settings :

let sections = gsap.utils.toArray(".block");

  gsap.to(sections, {
    xPercent: -100 * (sections.length - 1),
    ease: "none",
    scrollTrigger: {
      trigger: ".container",
      pin: true,
      scrub: 1,
      //snap: 1 / (sections.length - 1),
      // base vertical scrolling on how wide the container is so it feels more natural.
      end: "+=3000",
    }
  });

const projectSection = document.querySelector(".project");
  const projectContent = gsap.utils.toArray(".project__dynamic");
  // Vertical scrolling within the project section
  gsap.to(projectContent, {
    yPercent: -100 * (projectContent.length - 1),
    ease: "none",
    scrollTrigger: {
      trigger: projectSection,
      start: "top", 
      end: "+=300%", // Adjust the end point according to your layout
      scrub: true,
      pin: true,
      markers: true,
      onEnter: () => console.log("Entered project section"),
      onLeaveBack: () => console.log("Exited project section")
    }
  });

Codepen

Upvotes: 0

Views: 91

Answers (0)

Related Questions