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

              
                <section class="header">
  <h1>Header</h1>
</section>

<section class="video-container">
  <video src="https://tracta-codepen-assets.s3.ap-southeast-2.amazonaws.com/video.mp4" muted class="video-scroll"></video>
</section>

<section class="footer">
  <h1>Footer</h1>
</section>
              
            
!

CSS

              
                * {
  font-family: sans-serif;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

html {
  background-color: #000000;
}

body {
  overflow-x: hidden;
}

h1 {
  color: #ffffff;
  font-size: 3rem;
}

section {
  width: 100%;
  height: 100%;
  min-height: 500px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
}
              
            
!

JS

              
                //--- Credit to @shshaw for orginal video scroll code - https://codepen.io/shshaw/pen/vYKBPbv/9e810322d70c306de2d18237d0cb2d78

console.clear();
/* The encoding is super important here to enable frame-by-frame scrubbing. */

// ffmpeg -i ~/Downloads/Toshiba\ video/original.mov -movflags faststart -vcodec libx264 -crf 23 -g 1 -pix_fmt yuv420p output.mp4
// ffmpeg -i ~/Downloads/Toshiba\ video/original.mov -vf scale=960:-1 -movflags faststart -vcodec libx264 -crf 20 -g 1 -pix_fmt yuv420p output_960.mp4


gsap.registerPlugin(ScrollTrigger)

let videoScroll = document.querySelector(".video-scroll"),
    frameNumber = 0,
    src = videoScroll.currentSrc || videoScroll.src


videoScrollTL = gsap.timeline({
  defaults: { duration: 1 },
  scrollTrigger: {
    trigger: ".video-container",
    pin: true,
    start: "top top",
    end: "+=100%",
    scrub: true,
    markers: true,
    onUpdate: self => {
      frameNumber = self.progress / 14 * 100 - 1; //this takes fine tuning divide your videos FPS by two. My video's FPS was 30, 14 was the sweet spot. -1 fixes an issue on safari where the video disappears at the end of the scrollTrigger
      videoScroll.currentTime = frameNumber;
    }
  }
});		    

/* Make sure the video is 'activated' on iOS */
function once(el, event, fn, opts) {
  var onceFn = function (e) {
    el.removeEventListener(event, onceFn);
    fn.apply(this, arguments);
  };
  el.addEventListener(event, onceFn, opts);
  return onceFn;
}			    

once(document.documentElement, "touchstart", function (e) {
  videoScroll.play();
  videoScroll.pause();
});

//make sure video has loaded
once(videoScroll, "loadedmetadata", function () {
  videoScrollTL.fromTo(videoScroll, { currentTime: 0 }, { currentTime: videoScroll.duration - 0.10 });
});

//When first coded, the Blobbing was important to ensure the browser wasn't dropping previously played segments, but it doesn't seem to be a problem now. Possibly based on memory availability?
setTimeout(function () {
  if (window["fetch"]) {
    fetch(src).then(function (response) {
      return response.blob();
    }).then(function (response) {
      var blobURL = URL.createObjectURL(response);
      var t = videoScroll.currentTime;
      once(document.documentElement, "touchstart", function (e) {
        videoScroll.setAttribute("src", blobURL);
        videoScroll.currentTime = t + 0.01;
      });
    });
  }
}, 0);
              
            
!
999px

Console