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

              
                <div class="hero">
    <h1> Image Sequence Animation</h1>
</div>
<div class="hero">
    <h1> Image Sequence Animation</h1>
</div>
<div class="hero">
    <h1> Image Sequence Animation</h1>
</div>

<section class="hero-sequence-wrapper">
    <div class="container-fluid px-0 set-height">
        <div class="hero-sequence">
            <div class="sequence-element sticky-element">
                <!-- onclick it will popup a video -->
                <div class="sequence-youtube-icon " data-toggle="modal" data-target="#sequence-video">
                    <img alt="" class="" src="">
                </div>
                <canvas width="1920" height="400"></canvas>
            </div>
        </div>
    </div>
</section>

<footer class="mt-5">
     Image Sequence Animation Ends Here
</footer>
              
            
!

CSS

              
                .hero {
    background: black;
    padding: 40px;
    text-align: center;
    margin: 40px 0px;
}
.hero h1 {
    color: #fff;
}
.hero-sequence {
    height: 430vh;
}

.sticky-element {
    position: sticky;
    top: 0;
    overflow: hidden;
    display: flex;
    place-items: center;
    padding: 100px 0px;
}

footer {
    background: black;
    color: #fff;
    font-weight: 700;
    font-size: 40px;
    height: 400px;
    display: grid;
    place-items: center;
}
              
            
!

JS

              
                const canvas = document.querySelector('canvas')
const ctx = canvas.getContext('2d')
const heroSequence = document.querySelector('.hero-sequence')
const images = []
const frameCount = 130
const prepareImages = () => {
    for (var i = 0; i < frameCount; i++) {
      const image = new Image()
      image.src = `./img/${i}.jpg`
      images.push(image)

      if (i === 0) {
        images[i].onload = () => drawImage(0)
      }
    }
}

const drawImage = frameIndex => {
    ctx.drawImage(images[frameIndex], 0, 0)
}

prepareImages()

window.addEventListener('scroll', () => {
    const scrollTop = document.documentElement.scrollTop - heroSequence.offsetTop;
    // const maxScrollTop = heroSequence.scrollHeight - window.innerHeight;
    const maxScrollTop = heroSequence.scrollHeight - window.innerHeight;
    const scrollFraction = scrollTop / maxScrollTop;
    // const frameIndex = Math.floor(window.scrollY / (window.innerHeight / images.length));
    const frameIndex = Math.max(0, Math.min(frameCount - 1, Math.ceil(scrollFraction * frameCount)));

    images[frameIndex].onload = () => drawImage(frameIndex);
    requestAnimationFrame(() => drawImage(frameIndex));
});
              
            
!
999px

Console