Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <canvas id="animation" /></canvas>
<main>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eros arcu, feugiat ut cursus sit amet, sagittis et massa. Ut non rhoncus tellus. Mauris tincidunt, tellus ut tempus imperdiet, est arcu ultrices elit, id cursus arcu leo sed tortor. Suspendisse et maximus mauris. Sed sit amet gravida metus. Vestibulum vel augue mattis velit hendrerit accumsan ac ut enim. Duis id sem metus. Nullam tristique mattis nulla, at scelerisque massa vulputate a. Integer convallis pellentesque turpis quis interdum. Integer non commodo lectus. Mauris tincidunt, tellus ut tempus imperdiet.</p>
  <p>Sed congue vulputate lacus, et ultrices felis faucibus sed. Sed interdum, massa eu fringilla tristique, magna risus fermentum nisl, quis facilisis tortor magna tincidunt ligula. Pellentesque molestie orci quis fermentum pharetra. Sed et turpis egestas, rhoncus augue in, dignissim tortor. Sed nec consequat tortor. Donec euismod semper nisl id blandit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;</p>
  <p>Aenean nec sodales eros, a consequat orci. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a suscipit dolor, non suscipit nisi. Donec laoreet magna at dolor feugiat ullamcorper. Sed velit leo, vestibulum in viverra in, imperdiet sit amet arcu. Suspendisse non dolor nec eros imperdiet porttitor. Donec hendrerit tellus a vestibulum hendrerit. Curabitur ut cursus leo. Nunc mi tortor, molestie eget tellus ut, sodales commodo tellus.</p>
  <p>Pellentesque euismod, nunc vel suscipit dictum, urna ligula efficitur orci, id consectetur neque sem maximus justo. Mauris lobortis rutrum est at eleifend. Nam efficitur condimentum enim. Praesent quis egestas justo. Morbi facilisis ex in turpis dictum, sit amet lobortis dui luctus. Integer malesuada tellus eget nulla lobortis, ut ultrices erat gravida. Phasellus ut dolor et libero rhoncus ullamcorper ut sit amet enim. Curabitur molestie mollis nisl, eget vulputate elit sollicitudin et. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
  <p>In aliquam, nibh vitae venenatis sodales, velit justo tristique dui, vel rutrum turpis dui quis leo. Praesent tortor sem, convallis a odio nec, rhoncus elementum dolor. Aenean auctor vitae neque non eleifend. Nulla sit amet consequat nulla. Nunc id cursus enim. Ut nulla dolor, pellentesque semper enim at, semper fringilla nisl. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla sit amet magna sem. Vivamus ullamcorper dui dolor, sit amet iaculis sem rutrum vitae. Sed euismod sapien at tristique tempus. Pellentesque facilisis non est sed sagittis. Sed posuere semper tellus, ac lobortis est dignissim ac.</p>
</main>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html {
  height: 100vh;
  scroll-behavior: smooth;
}

body {
  background: #000;
}

canvas {
  position: fixed;
  top: 0;
  left: 30px;
  max-width: 100vw;
  height: 100vh;
  width: 50vw;
  object-fit: contain;
  filter: invert(1);
}

main {
  width: 50%;
  float: right;
  color: white;
  font-family: sans-serif;
  padding: 0 50px;
}

main p {
  margin: 22vh 0;
  line-height: 1.6em;
}

@media only screen and (max-width: 550px) {

main {
  width: 100%;
  position: relative;
  z-index: 2;
  padding-top: 75vh;
}
  main p {
  background: rgba(0,0,0,0.5);
    padding: 15px 0;
    margin: 15vh 0;
}

canvas {
  width: calc(100% - 100px);
  left: 50px;
  }
}
              
            
!

JS

              
                const html = document.documentElement;
const canvas = document.getElementById("animation");
const context = canvas.getContext("2d");

const frameCount = 40;
const currentFrame = index => (
  `https://cybersandbox.ca/assets/frames/frame_${index.toString().padStart(2, '00')}.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=539;
canvas.height=475;
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