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

              
                <h1>Animations + ScrollTrigger</h1>
<section class="page-content">
  <h2>PAGE CONTENT</h2>
  <p>
    Maecenas finibus pharetra ipsum, eu facilisis ex ultrices a. Ut gravida justo eu metus fermentum, in gravida nisi ullamcorper. Maecenas et mi id nisl dignissim finibus.
  </p>
</section>

<section class="animated-hero-wrapper">

  <div id="animatedHero" ref="animatedHero" class="animated-hero-container">

    <div ref="animatedHeroColumnCornerLeft" class="animated-hero-corner-left">
      <div class="animated-hero-corner"></div>
    </div>
    <div ref="animatedHeroColumnLeft" class="animated-hero-column-left">
      <div class="animated-hero-column animated-hero-column__top"></div>
      <div class="animated-hero-column animated-hero-column__bottom"></div>
    </div>

    <figure style="display: flex" ref="heroVideo" class="animated-hero-video">
      <video ref="heroVideoPlayer" class="animated-hero-video__player" src="https://videos.pexels.com/video-files/7279180/7279180-sd_960_406_25fps.mp4" playsinline="true" webkit-playsinline="true" preload="auto" muted="muted" autoplay="autoplay" loop="loop">
      </video>
    </figure>

    <div ref="animatedHeroColumnRight" class="animated-hero-column-right">
      <div class="animated-hero-column animated-hero-column__top"></div>
      <div class="animated-hero-column animated-hero-column__bottom"></div>
    </div>
    <div ref="animatedHeroColumnCornerRight" class="animated-hero-corner-right">
      <div class="animated-hero-corner"></div>
    </div>

  </div>

</section>







<section class="page-content">
  <h2>OTHER PAGE CONTENT</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque hendrerit pretium nunc, elementum gravida mi tempus id. Donec eu quam in lorem elementum aliquet quis ac nulla. In ac tellus aliquet, scelerisque felis porttitor, tristique tellus. Nam scelerisque risus mauris, id iaculis massa eleifend eu. Nam neque lectus, euismod vel nisi non, sollicitudin eleifend enim.
  </p>
  <p>
    Maecenas finibus pharetra ipsum, eu facilisis ex ultrices a. Ut gravida justo eu metus fermentum, in gravida nisi ullamcorper. Maecenas et mi id nisl dignissim finibus.
  </p>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque hendrerit pretium nunc, elementum gravida mi tempus id. Donec eu quam in lorem elementum aliquet quis ac nulla. In ac tellus aliquet, scelerisque felis porttitor, tristique tellus. Nam scelerisque risus mauris, id iaculis massa eleifend eu. Nam neque lectus, euismod vel nisi non, sollicitudin eleifend enim.
  </p>
  <p>
    Maecenas finibus pharetra ipsum, eu facilisis ex ultrices a. Ut gravida justo eu metus fermentum, in gravida nisi ullamcorper. Maecenas et mi id nisl dignissim finibus.
  </p>

  <h2>OTHER CONTENT</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque hendrerit pretium nunc, elementum gravida mi tempus id. Donec eu quam in lorem elementum aliquet quis ac nulla. In ac tellus aliquet, scelerisque felis porttitor, tristique tellus. Nam scelerisque risus mauris, id iaculis massa eleifend eu. Nam neque lectus, euismod vel nisi non, sollicitudin eleifend enim.
  </p>
  <p>
    Maecenas finibus pharetra ipsum, eu facilisis ex ultrices a. Ut gravida justo eu metus fermentum, in gravida nisi ullamcorper. Maecenas et mi id nisl dignissim finibus.
  </p>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque hendrerit pretium nunc, elementum gravida mi tempus id. Donec eu quam in lorem elementum aliquet quis ac nulla. In ac tellus aliquet, scelerisque felis porttitor, tristique tellus. Nam scelerisque risus mauris, id iaculis massa eleifend eu. Nam neque lectus, euismod vel nisi non, sollicitudin eleifend enim.
  </p>
  <p>
    Maecenas finibus pharetra ipsum, eu facilisis ex ultrices a. Ut gravida justo eu metus fermentum, in gravida nisi ullamcorper. Maecenas et mi id nisl dignissim finibus.
  </p>
</section>
              
            
!

CSS

              
                :root {
  --videoInitialTop: 12%;
  --columnsLeftRightInitialTop: 15%;
  --cornersInitialTop: 18%;
}

body {
  font-family: Avenir, sans-serif;
  background-color: #0e100f;
  color: #fffce1;
}

.animated-hero-wrapper {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  max-width: 100%;
  height: 300vh;
  min-height: 300px;
  margin: 0;
  margin-bottom: 60px;
  padding: 0;

  overflow: hidden;
  
  .animated-hero-container {
    width: 100%;
  }
}

figure.animated-hero-video {
  aspect-ratio: 16 / 9;
  position: relative;
  top: var(--videoInitialTop);
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
}

.animated-hero-video__player {
  aspect-ratio: 16 / 9;
  object-fit: cover;
  width: 100%;
  height: auto;
  min-width: 100%;
  min-height: 100%;

  clip-path: inset(0 40% 0 40%);
}

/* aspect ratios */
.animated-hero-corner {
  aspect-ratio: 1 / 1;
}
.animated-hero-column {
  &__top {
    aspect-ratio: 4 / 3;
  }
  &__bottom {
    aspect-ratio: 1 / 1;
  }
}

/** Left side of hero **/
.animated-hero-corner-left {
  position: absolute;
  top: var(--cornersInitialTop);
  left: -25%;
  width: 36%;
  height: 200px;
}

.animated-hero-column-left {
  display: flex;
  flex-direction: column;
  gap: 30px;
  position: absolute;
  top: var(--columnsLeftRightInitialTop);
  left: 15%;
  width: 20%;
}

/** Right side of hero **/
.animated-hero-corner-right {
  position: absolute;
  top: var(--cornersInitialTop);
  right: -10%;
  width: 20%;
  height: 200px;
}

.animated-hero-column-right {
  display: flex;
  flex-direction: column;
  // height: 50%;
  gap: 30px;
  position: absolute;
  top: var(--columnsLeftRightInitialTop);
  right: 15%;
  width: 20%;
}

/** Shared classes **/
.animated-hero-column {
  &:nth-child(odd) {
    height: 60%;
    background-color: rgb(71, 71, 239);
  }
  &:nth-child(even) {
    height: 40%;
    background-color: rgb(244, 176, 48);
  }

  > img {
    object-fit: cover;
    width: 100%;
    height: auto;
    min-width: 100%;
    min-height: 100%;
  }
}

.animated-hero-corner {
  width: 100%;
  height: 100%;
  background-color: rgb(237, 48, 48);
}

h1,
.page-content {
  // display: none;
  padding: 20px 40px;
}

              
            
!

JS

              
                const animatedHeroContainer = ".animated-hero-container";
const animatedHeroCornerLeft = ".animated-hero-corner-left";
const animatedHeroColumnLeft = ".animated-hero-column-left";
const animatedHeroVideoPlayer = ".animated-hero-video__player";
const animatedHeroColumnRight = ".animated-hero-column-right";
const animatedHeroCornerRight = ".animated-hero-corner-right";

const SQUARES_UP_DURATION = 1.2;
const SQUARES_ANIM_DURATION = 2;
const VIDEO_PIN_DURATION = 1.5;

const tl = gsap.timeline({
  scrollTrigger: {
    id: "box",
    trigger: ".animated-hero-container",
    start: "top top",
    end: "+=1500",
    scrub: 1
    //markers: {
    // 	startColor: 'green',
    // 	endColor: 'orange',
    // 	fontSize: '2.5rem',
    // },
  }
});

// Side-squares - up animation
tl.to(
  animatedHeroCornerLeft,
  {
    yPercent: -120,
    ease: "none",
    duration: SQUARES_UP_DURATION
  },
  0
);
tl.to(
  animatedHeroColumnLeft,
  {
    yPercent: -55,
    ease: "none",
    duration: SQUARES_UP_DURATION
  },
  0
);

tl.to(
  animatedHeroCornerRight,
  {
    yPercent: -120,
    ease: "none",
    duration: SQUARES_UP_DURATION
  },
  0
);
tl.to(
  animatedHeroColumnRight,
  {
    yPercent: -55,
    ease: "none",
    duration: SQUARES_UP_DURATION
  },
  0
);

// Side-squares - side animation
tl.to(
  animatedHeroCornerLeft,
  { left: "-60%", duration: SQUARES_ANIM_DURATION, ease: "none" },
  SQUARES_UP_DURATION
);
tl.to(
  animatedHeroColumnLeft,
  { left: "-30%", duration: SQUARES_ANIM_DURATION, ease: "none" },
  SQUARES_UP_DURATION
);
tl.to(
  animatedHeroColumnRight,
  { right: "-30%", duration: SQUARES_ANIM_DURATION, ease: "none" },
  SQUARES_UP_DURATION
);
tl.to(
  animatedHeroCornerRight,
  { right: "-60%", duration: SQUARES_ANIM_DURATION, ease: "none" },
  SQUARES_UP_DURATION
);

/*
 * VIDEO
 */

const tlVideoUp = gsap.timeline({
  scrollTrigger: {
    id: "v-up",
    trigger: ".animated-hero-container",
    start: "top top",
    end: "+=450",
    scrub: 1
  }
});

// Video - up animation
tlVideoUp.to(".animated-hero-video__player", { y: -460, duration: 1.5 }, 0);

const tlVideo = gsap.timeline({
  scrollTrigger: {
    id: "video",
    trigger: ".animated-hero-container",
    pin: true,
    start: "top top",
    end: "+=1360",
    scrub: 1,
    markers: {
      startColor: "green",
      endColor: "orange",
      fontSize: "2.5rem"
    }
  }
});

// Video - expand animation
tlVideo.from(
  ".animated-hero-video__player",
  {
    clipPath: "inset(0 40% 0 40%)",
    ease: "none",
    duration: SQUARES_ANIM_DURATION,
  },
  VIDEO_PIN_DURATION
);

tlVideo.to(
  ".animated-hero-video__player",
  {
    clipPath: "inset(0% 0%)",
    ease: "none",
    duration: SQUARES_ANIM_DURATION,
  },
  VIDEO_PIN_DURATION
);

/* end: () =>
        `+=${
          document.querySelector(".animated-hero-video").offsetHeight *
          VIDEO_PIN_DURATION
        }`,
      */

              
            
!
999px

Console