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

              
                <main>

  <h1>Minify Video on Scroll.</h1>

  <p>ScrollTrigger and Flip plugin go perfectly together. Scroll down to see the video smoothly toggle between relative and fixed position.</p>
  
  <div class="video-container">
    <video autoplay loop muted class="video" src="https://assets.codepen.io/16327/smol-vid.webm">
    </video>
  </div>
  
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>
  
  <p>Vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>

  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Doloremque quis sequi eius optio unde nesciunt fugiat cum impedit? Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>
  
  <p>Vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>

  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>

  <p>Dolor sit amet consectetur adipisicing elit. Doloremque quis sequi eius optio unde nesciunt fugiat cum impedit? Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Doloremque quis sequi eius optio unde nesciunt fugiat cum impedit? Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>

  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>
  
  <p>Vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>

  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Doloremque quis sequi eius optio unde nesciunt fugiat cum impedit? Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Tempore asperiores suscipit libero repudiandae id repellat nostrum molestias laudantium autem error!</p>
  
  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>
  
  <p>Vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>

  <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ab, velit quam. Quidem accusantium quod distinctio cumque expedita accusamus delectus doloremque laborum sapiente, et reprehenderit! Vero facere eveniet accusamus architecto qui. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit ab, vel veritatis nobis aut fugiat, adipisci magni expedita recusandae libero ex nostrum sed aperiam quidem, beatae quos! Ipsa, possimus veniam! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Temporibus voluptatum porro quaerat voluptatem ad iusto modi amet labore voluptate soluta, dicta fugiat praesentium assumenda rem. Voluptas porro libero quasi fugit?</p>
</main>
              
            
!

CSS

              
                /* @link https://utopia.fyi/type/calculator?c=320,16,1.2,1140,20,1.667,2,0,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l */
@import url("https://fonts.googleapis.com/css2?family=Lato&family=Spectral:ital,wght@1,700&display=swap");

:root {
  --fluid-min-width: 320;
  --fluid-max-width: 1140;

  --fluid-screen: 100vw;
  --fluid-bp: calc(
    (var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) /
      (var(--fluid-max-width) - var(--fluid-min-width))
  );
}

@media screen and (min-width: 1140px) {
  :root {
    --fluid-screen: calc(var(--fluid-max-width) * 1px);
  }
}

:root {
  --f-0-min: 16;
  --f-0-max: 20;
  --step-0: calc(
    ((var(--f-0-min) / 16) * 1rem) + (var(--f-0-max) - var(--f-0-min)) *
      var(--fluid-bp)
  );

  --f-1-min: 19.2;
  --f-1-max: 24;
  --step-1: calc(
    ((var(--f-1-min) / 16) * 1rem) + (var(--f-1-max) - var(--f-1-min)) *
      var(--fluid-bp)
  );

  --f-2-min: 38;
  --f-2-max: 62;
  --step-2: calc(
    ((var(--f-2-min) / 16) * 1rem) + (var(--f-2-max) - var(--f-2-min)) *
      var(--fluid-bp)
  );
}

body {
  margin: 1rem;
  line-height: 1.65;
  font-size: var(--step-0);
  font-family: "Lato", sans-serif;
  background: black;
  color: white;
}

h1 {
  font-size: 3.75rem;
  line-height: 1.15;
  font-size: var(--step-2);
  font-family: "Spectral", serif;
}

p:first-of-type {
  font-size: var(--step-1);
  line-height: 1.4;
  padding-bottom: 2rem;
  border-bottom: solid 3px #4bd3cd;
}

main {
  max-width: 750px;
  margin: 0 auto;
  padding: 1.75rem 1rem 0;
}

.video-container {
  margin: 2rem 0;
}

.video-container::before {
  float: left;
  padding-top: 56.20608899297423%;
  content: "";
}

.video-container::after {
  display: block;
  content: "";
  clear: both;
}

.video {
  width: 100%;
  height: auto;
  vertical-align: bottom;
  will-change: transform;
}

video.fixed {
  width: 300px;
  position: fixed;
  bottom: 10px;
  left: 10px;
}

              
            
!

JS

              
                gsap.registerPlugin(Flip, ScrollTrigger);

let video = document.querySelector(".video");

ScrollTrigger.create({
  trigger: ".video-container",
  start: "90% top",
  onEnter: () => toggleVideo("add"),
  onLeaveBack: () => toggleVideo("remove")
});

function toggleVideo(action) {
  let state = Flip.getState(video);
  video.classList[action]("fixed");
  Flip.from(state, {
    scale: true,
    ease: "power3.out",
    duration: 1
  });
}

              
            
!
999px

Console