Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <section class="first">
    <div class="outer">
      <div class="inner">
        <div class="bg one">
          <div class="overlay"></div>
          <div class="text lineUp">
            <h5>LOREM IPSUM</h5>
            <h2>INSPIRED BY A LOREM IPSUM</h2>
            <h5>LOREM IPSUM LOREM IPSUM</h5>
          </div>
        </div>
      </div>
    </div>
  </section>

  <section class="second">
    <div class="outer">
      <div class="inner">
        <div class="bg">
          <div class="overlay"></div>
          <div class="text lineUp">
            <h5>LOREM IPSUM LOREM IPSUM</h5>
            <h2>LOREM IPSUM LOREM IPSUM</h2>
            <h5>LOREM IPSUM LOREM IPSUM</h5>
          </div>
        </div>
      </div>
    </div>
  </section>
  <section class="third">
    <div class="outer">
      <div class="inner">
        <div class="bg">
          <h1 class="title anim-lineUp">LOREM IPSUM LOREM IPSUM</h1>
          <canvas id="hero-lightpass"></canvas>
        </div>
      </div>
    </div>
  </section>

 <section class="fourth">
    <div class="outer">
      <div class="inner">
        <div class="bg">
          <div class="overlay"></div>
          <div class="text lineUp">
            <h5>LOREM IPSUM LOREM IPSUM</h5>
            <h2>LOREM IPSUM LOREM IPSUM</h2>
            <h5>LOREM IPSUM LOREM IPSUM</h5>
          </div>
        </div>
      </div>
    </div>
  </section>

</body>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  user-select: none;
}

body {
  margin: 0;
  padding: 0;
  height: 100vh;
  color: white;
  background: black;
  font-family: "Cormorant Garamond", serif;
  text-transform: uppercase;
}

h2 {
  font-size: clamp(1rem, 5vw, 5rem);
  font-weight: 400;
  text-align: center;
  letter-spacing: 0.5em;
  margin-right: -0.5em;
  color: hsl(0, 0, 80%);
  width: 90vw;
  max-width: 1200px;
}

header {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5%;
  width: 100%;
  z-index: 3;
  height: 7em;
  font-family: "Bebas Neue", sans-serif;
  font-size: clamp(0.66rem, 2vw, 1rem);
  letter-spacing: 0.5em;
}

section {
  height: 100%;
  width: 100%;
  top: 0;
  position: fixed;
  visibility: hidden;
  will-change: transform;
}

.first {
  background: red;
}

.second {
  background: orange;
}

.third {
  background: yellow;
}

.fourth {
  background: green;
}

.outer,
.inner {
  width: 100%;
  height: 100%;
  overflow-y: hidden;
  will-change: transform;
}

.overlay {
  background: black;
  opacity: 0.7;
  object-fit: cover;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transform: unset;
}

.bg {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.bg video,
.bg .front {
  position: absolute;
  object-fit: cover;
  width: 100%;
  height: 100vh;
  top: 0;
  left: 0;
}

.horizontal {
overscroll-behavior: none;
        width: 600%;
        height: 100%;
        display: flex;
        flex-wrap: nowrap;
}

.bg h2 {
  z-index: 2;
}

.bg .clip-text {
  overflow: hidden;
}

.bg .title {
  position: absolute;
  z-index: 100;
  top: 20%;
  /* left: 50%; */
  font-size: 55px;
  text-align: center;
  width: 100%;
}

.text {
  position: absolute;
  top: 10px;
  z-index: 1000;
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

h1{
  color: white;
}

@keyframes fadeOut {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

              
            
!

JS

              
                gsap.registerPlugin(Observer);

let sections = document.querySelectorAll("section"),
  content = document.querySelectorAll(".bg"),
  headings = gsap.utils.toArray(".section-heading"),
  outerWrappers = gsap.utils.toArray(".outer"),
  innerWrappers = gsap.utils.toArray(".inner"),
  currentIndex = -1,
  wrap = gsap.utils.wrap(0, sections.length - 1),
  animating;

function gotoSection(index, direction) {
  console.log("current Index: ", currentIndex);
  console.log("index: ", index);
  index = wrap(index); // make sure it's valid
  animating = true;

  let fromTop = direction === -1,
    dFactor = fromTop ? -1 : 1,
    tl = gsap.timeline({
      defaults: {
        duration: 1.25,
        ease: "power1.inOut"
      },
      onComplete: () => (animating = false)
    });

  function zoomInScrolling() {
    gsap.set(sections[currentIndex], { zIndex: 0 });
    tl.to(content[currentIndex], { scale: 5 }).set(sections[currentIndex], {
      autoAlpha: 1
    });

    gsap.set(sections[index], { autoAlpha: 1, zIndex: 1 });

    tl.fromTo(
      [outerWrappers[index], innerWrappers[index]],
      {
        opacity: 0
      },
      {
        opacity: 1
      },
      0
    ).fromTo(content[index], { scale: 1.2 }, { scale: 1 }, 0);

    currentIndex = index;
    console.log(index);
  }

  if (currentIndex == -1 || currentIndex == 0 || currentIndex == 1) {
    zoomInScrolling();
  } else if (currentIndex == 2) {
    animating = false;
    ScrollTrigger.create({
      // trigger: '.third',
      pin: ".third",
      start: "center center",
      end: "+=4000 bottom",
      scrub: 1,
      onEnter: (self) => {
        console.log("it is starting");
        moveAnimate();
      },
      onLeave: (self) => {
        console.log("it is done");
        listening = true;
        gsap.set(sections[currentIndex], { opacity: 0 });
        currentIndex = 3;
        zoomInScrolling();
      }
    });
  }
}

Observer.create({
  type: "wheel, touch",
  wheelSpeed: -1,
  ignore: ".third",
  onDown: () => !animating && gotoSection(currentIndex - 1, -1),
  onUp: () => !animating && gotoSection(currentIndex + 1, 1),
  tolerance: 10
  // preventDefault: true
});

gotoSection(0, 1);

function moveAnimate() {
  const html = document.documentElement;
  const canvas = document.getElementById("hero-lightpass");
  const context = canvas.getContext("2d");

  const frameCount = 129;
  const currentFrame = (index) =>
    `https://www.apple.com/105/media/us/airpods-pro/2019/1299e2f5_9206_4470_b28e_08307a42f19b/anim/sequence/large/01-hero-lightpass/${(
      index + 1
    )
      .toString()
      .padStart(4, "0")}.jpg`;

  const preloadImages = () => {
    for (let i = 1; i < frameCount; i++) {
      const img = new Image();
      img.src = currentFrame(i);
    }
  };

  const img = new Image();
  img.src = currentFrame(1);
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  img.onload = function () {
    context.drawImage(img, 0, 0);
  };

  const updateImage = (index) => {
    img.src = currentFrame(index);
    context.drawImage(img, 0, 0);
  };

  window.addEventListener("scroll", () => {
    const scrollTop = html.scrollTop;
    const maxScrollTop = html.scrollHeight - window.innerHeight;
    const scrollFraction = scrollTop / maxScrollTop;
    const frameIndex = Math.min(
      frameCount - 1,
      Math.ceil(scrollFraction * frameCount)
    );

    requestAnimationFrame(() => updateImage(frameIndex + 1));
  });

  preloadImages();
}

              
            
!
999px

Console