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

              
                <canvas class="animContainer" id="animContainerID"></canvas>

<div class="bodyContainer" id="bodyContainerID">

  <div class="hed">
    <p>(scroll to see animation)</p>
  </div>


  <div class="controls">

    <div id="sliderWrapper">
      <div id="slider"></div>
    </div>

    <div class="buttons">
      <button class="jumpBtn" value="0">Jump to START (fr 0)</button>
      <button class="jumpBtn" value="14">Jump to CALLOUT 01</button>
      <button class="jumpBtn" value="39">Jump to CALLOUT 02</button>
      <button class="jumpBtn" value="64">Jump to CALLOUT 03</button>
      <button class="jumpBtn" value="87">Jump to CALLOUT 04</button>
      <button class="jumpBtn" value="160">Jump to END (fr 160)</button>
    </div>

    <div class="buttons">
      <button id="play">play()</button>
      <button id="pause">pause()</button>
      <button id="resume">resume()</button>
      <button id="reverse">reverse()</button>
      <button id="restart">restart</button>
    </div>

  </div>


  <div class="stats">
    <p class="framecount">frame: </p>
    <p class="scrollProgress">scrollProgress: </p>
    <p class="scrollPosition">scrollPosition: </p>
  </div>


  <div class="callout" id="callout01ID">
    <h2>Callout 01</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nunc quam, aliquet quis turpis viverra, feugiat ultrices quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et purus augue.
  </div>

  <div class="callout" id="callout02ID">
    <h2>Callout 02</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nunc quam, aliquet quis turpis viverra, feugiat ultrices quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et purus augue.
  </div>

  <div class="callout" id="callout03ID">
    <h2>Callout 03</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nunc quam, aliquet quis turpis viverra, feugiat ultrices quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et purus augue.
  </div>

  <div class="callout" id="callout04ID">
    <h2>Callout 04</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nunc quam, aliquet quis turpis viverra, feugiat ultrices quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et purus augue.
  </div>

</div>

              
            
!

CSS

              
                html,
body {
    background: #000000;

    font-family: Arial, Helvetica, sans-serif;

    margin: 0px;
    padding: 0px;
}

html {
    height: 100vh;
}

body {
    height: 5000px;
}

.animContainer {
    width: 960px;
    height: 540px;

    max-width: 100vw;
    max-height: 100vh;

    margin: 0 auto;

    position: fixed;
    left: 50%;

    transform: translate(-50%, 50px);
}

.bodyContainer {
    width: 960px;
    height: 620px;

    position: fixed;
    top: 0;
    left: 50%;

    transform: translate(-50%, 0);

    .hed {
        text-align: center;
        color: #ffffff;

        width: 100%;

        margin: 0 auto;
        padding: 0;

        transform: translate(0, 20px);

        z-index: 5;

        h1 {
            border: 5px solid black;

            font-size: 1.5em;
            line-height: 0.8em;
            text-transform: uppercase;

            margin: 0;
            padding: 0.2em;
        }

        p {
            font-size: 1em;

            margin: 0;
            padding: 0;
        }
    }

    .controls {
        width: 100%;

        position: fixed;
        transform: translate(0, 575px);

        .buttons,
        .buttonsNG {
            font-size: 1.75em;
            text-align: center;
            color: #ffffff;

            margin: 0;
            padding: 10px 0;

            button {
                font-size: 0.5em;

                height: 30px;

                margin: 0;
                padding: 0 5px;
            }
        }

        .buttonsNG {
            border: 1px solid #ff00ff;
        }

        #sliderWrapper {
            margin: 0;
            padding: 0 0 20px 0;

            #slider {
                width: 100%;
            }
        }
    }

    .stats {
        font-family: monospace;
        color: #ffffff;

        width: 30%;
        height: 60px;

        margin: 0;
        padding: 0;

        position: relative;
        transform: translate(0, 480px);
        float: right;

        z-index: 5;

        p {
            border: 1px solid #333333;

            font-size: 1em;

            width: 100%;
            height: 33.333%;

            margin: 0;
            padding: 0;

            position: absolute;
            right: 0;
        }

        .scrollProgress {
            top: 33.3333%;
        }

        .scrollPosition {
            top: 66.6666%;
        }
    }

    .callout {
        background: #ffffff;
        background-position: center;
        background-repeat: no-repeat;

        width: 150px;
        height: 200px;

        margin: 0;
        padding: 10px 0 0 0;

        position: absolute;

        h2, p {
            text-align: left;

            width: 80%;

            margin: 0 auto;
            padding: 5px 0;

            display: flex;
            justify-content: center;
            align-items: center;

            position: relative;
        }

        h2 {
            font-size: 1.25em;
        }

        p {
            font-size: 0.75em;
        }
    }
}

              
            
!

JS

              
                // ========================= GLOBAL CONSTANTS / [dirty, dirty...] INIT/RESET =========================

const frameCount = 120;
const sliderStep = 0.0000000000000001;
let scrollPos = 0;

var restartClicked = false;

// gsap.set(window, { scrollTo: 0 });
gsap.set(window, { scrollTo: 1 });

// window.scrollTo(0, 0);
// window.scrollTo(0, 1);


// ========================= IMAGES =========================

const canvas = document.getElementById("animContainerID");
const context = canvas.getContext("2d");

canvas.width = 960;
canvas.height = 540;

const currentFrame = index => (
    `https://www.shigimcp.com/Xstage/building_blowout_1020/img/Haus1_render01/Haus1_${(index).toString().padStart(4, '0')}.png`
);

const images = []

const anim = {
    frame: 0,
    lastFrame: -1,
    totalFrames: frameCount,
    images: []
};

for (let i = 0; i <= frameCount; i++) {

    const img = new Image();

    img.src = currentFrame(i);
    images.push(img);
}


// ========================= FUNCTION: updateStats(thisFrame, thisProgress, thisScrollPos) =========================

function updateStats(thisFrame, thisProgress, thisScrollPos) {
    $(".framecount").html('frame: ' + thisFrame);
    $(".scrollProgress").html('scrollProgress: ' + thisProgress);
    $(".scrollPosition").html('scrollPosition: ' + thisScrollPos);
}


// ========================= FUNCTION: drawSprite() =========================

function drawSprite() {

    if (anim.frame === anim.lastFrame) {
        return;
    }

    context.clearRect(0, 0, canvas.width, canvas.height);
    context.drawImage(images[anim.frame], 0, 0);

    anim.lastFrame = anim.frame;

    const thisProgress = anim.frame / frameCount;
    scrollPos = (document.body.offsetHeight - window.innerHeight) * thisProgress;

    gsap.set(window, { scrollTo: (document.body.offsetHeight - window.innerHeight) * thisProgress });

    $("#slider").slider("value", thisProgress);

    updateStats(anim.frame, thisProgress, scrollPos);
}


// ========================= TIMELINE: animTimeline =========================

var animTimeline = gsap.timeline({
    paused: true,
    onUpdate: drawSprite,

    scrollTrigger: {
        // markers: true,
        scrub: true,

        onLeave: () => {
            animTimeline.pause()
        },

        onLeaveBack: () => {
            if (!restartClicked) {
                animTimeline.pause()
            }
            restartClicked = false;
        }

    },
});

animTimeline
    .to(anim, {
        duration: 1,
        frame: frameCount,
        ease: "none",
        snap: "frame",
    }
);


// ========================= TIMELINE: *NOT* a timeline, i.e. separate tweens =========================

const triggerStart01 = 1000;
const triggerStart02 = 1750;
const triggerStart03 = 2500;
const triggerStart04 = 3250;

const triggerEndDiff = 400;

const scrollerStart = 70;
const scrollerEnd = 90;


// - - - - - - - - - - - - - CALLOUT 01 v01 - - - - - - - - - - - - -

gsap.fromTo(["#callout01ID"],
    {
        x: 550,
        y: 0,
        scale: 0.75,
        autoAlpha: 0,
    },
    {
        id: "callout01",
        x: 750,
        // y: 0,
        scale: 1,
        autoAlpha: 1,

        duration: 0.5,

        scrollTrigger: {
            markers: true,
            trigger: "#callout01ID",
            start: () => "+=" + triggerStart01 + " " + scrollerStart + "%",
            end: () => "+=" + (triggerStart01 + triggerEndDiff) + " " + scrollerEnd + "%",

            // scrub: true,

            toggleActions: "play reverse play reverse",
        }
    }
);


// - - - - - - - - - - - - - CALLOUT 02 - - - - - - - - - - - - -

gsap.fromTo(["#callout02ID"],
    {
        x: 250,
        y: 100,
        scale: 0.75,
        autoAlpha: 0,
    },
    {
        id: "callout02",
        x: 50,
        // y: 100,
        scale: 1,
        autoAlpha: 1,

        duration: 0.5,

        scrollTrigger: {
            markers: true,
            trigger: "#callout02ID",
            start: () => "+=" + triggerStart02 + " " + scrollerStart + "%",
            end: () => "+=" + (triggerStart02 + triggerEndDiff) + " " + scrollerEnd + "%",

            // scrub: true,

            toggleActions: "play reverse play reverse",
        }
    }
);


// - - - - - - - - - - - - - CALLOUT 03 - - - - - - - - - - - - -

gsap.fromTo(["#callout03ID"],
    {
        x: 450,
        y: 250,
        scale: 0.75,
        autoAlpha: 0,
    },
    {
        id: "callout03",
        x: 650,
        // y: 250,
        scale: 1,
        autoAlpha: 1,

        duration: 0.5,

        scrollTrigger: {
            markers: true,
            trigger: "#callout03ID",
            start: () => "+=" + triggerStart03 + " " + scrollerStart + "%",
            end: () => "+=" + (triggerStart03 + triggerEndDiff) + " " + scrollerEnd + "%",

            // scrub: true,

            toggleActions: "play reverse play reverse",
        }
    }
);


// - - - - - - - - - - - - - CALLOUT 04 - - - - - - - - - - - - -

gsap.fromTo(["#callout04ID"],
    {
        x: 450,
        y: 300,
        scale: 0.75,
        autoAlpha: 0,
    },
    {
        id: "callout04",
        x: 250,
        // y: 300,
        scale: 1,
        autoAlpha: 1,

        duration: 0.5,

        scrollTrigger: {
            markers: true,
            trigger: "#callout04ID",
            start: () => "+=" + triggerStart04 + " " + scrollerStart + "%",
            end: () => "+=" + (triggerStart04 + triggerEndDiff) + " " + scrollerEnd + "%",

            // scrub: true,

            toggleActions: "play reverse play reverse",
        }
    }
);


// ========================= CONTROLS: SCRUBBER / SLIDER =========================

$("#slider").slider({
    range: false,
    min: 0,
    max: 1,
    step: sliderStep,

    slide: function (event, ui) {

        const thisProgress = ui.value;

        gsap.set(window, { scrollTo: (document.body.offsetHeight - window.innerHeight) * thisProgress });

        animTimeline.pause();
    }
});


// ========================= CONTROLS: JUMP BUTTONS =========================

$('.jumpBtn').each(function () {

    thisButton = $(this);

    thisButton.click(function () {

        const thisProgress = this.value / frameCount;

        gsap.to(window, { scrollTo: (document.body.offsetHeight - window.innerHeight) * thisProgress, duration: 0.5 });

        animTimeline.pause();
    });

})


// ========================= CONTROLS: TIMELINE BUTTONS - REF: https://codepen.io/akapowl/pen/qBNxyvy =========================

$(document).ready(function () {

    $('#play').click(function () { animTimeline.timeScale(0.25).play(); });
    $('#pause').click(function () { animTimeline.timeScale(0.25).pause(); });
    $('#resume').click(function () { animTimeline.timeScale(0.25).resume(); });
    $('#reverse').click(function () { animTimeline.timeScale(1).reverse(); });
    $('#restart').click(function () {
        restartClicked = true;
        animTimeline.timeScale(0.25).restart();
    });

});

              
            
!
999px

Console