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

              
                <div class="spacer"></div>
<div id="mark1"></div>
<div class="hero-fight-parallax placeholder">
    <div class="background"></div>
    <div class="monster">monster on hill</div>
    <div class="shadow-hero">hero on hill</div>
</div>
<div id="mark2"></div>
<div class="spacer"></div>
<div class="hero-fight-parallax fixed">
    <div class="stage">
    <div class="background"></div>
    <div class="monster" id="monster">monster on hill</div>
    <div class="shadow-hero" id="shadow-hero">hero on hill</div>
    </div>
</div>
              
            
!

CSS

              
                .spacer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.hero-fight-parallax {
    /* fight scene fills the screen when the parallax
       hits the sweet spot. */
    height: 200vh;
    background-color: grey;
    position: relative;
    overflow: hidden;
    
    &.fixed {
        height: 100vh;
        display: none;
        // pointer-events: none;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        overflow: hidden;
        
        .stage {
            height: 100vh;
            width: 100%;
            position:relative;
        }
        
        &.visible {
            display: block;
        }
    }
    
    .background {
        background: url("https://static.giantbomb.com/uploads/original/19/199153/2550331-bit+trip+runner.jpg");
        width: 100vw;
        height: 100vh;
        background-size: cover;
        background-position: bottom;
        z-index: 0;
        position: absolute;
        top: 0;
    }
    
    .monster {
        width: 400px;
        height: 300px;
        background-color: pink;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
    }
    
    .shadow-hero {
        background-color: black;
        width: 200px;
        height: 200px;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        color: white;
    }
}

html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/154887/Routetut.png);
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", function(event) {

    window.addEventListener("load", function(){

        var durationValueCache;
        var animation = fightAnimation();

        // fight scene duration should change based on viewport height
        // animation should be set to a total of 2 viewport heights
        // but for now, it's a single screen
        $(window).on('resize', updateDuration);
        $(window).triggerHandler('resize');

        console.clear();

        var controller = new ScrollMagic.Controller();

        var scene1 = new ScrollMagic.Scene({
            triggerElement: '#mark1',
            //duration: 500,
            offset: 0, // -64, // header size
            triggerHook: 0 //'when fight scene takes over the screen'
        })
        .duration(getDuration)
        .setTween(animation)
        .on('enter', function() {
            console.log('fight scene!');
        })
        .addTo(controller);

        function fightAnimation() {
            var monster = document.querySelector("#monster");
            var hero = document.querySelector("#shadow-hero");

            var fightAnimation = new TimelineLite()
            .set('.hero-fight-parallax.fixed', {
                display: 'block',
                immediateRender:false
            })
            .set('.hero-fight-parallax.placeholder .background', {
                top: 0,
                bottom: 'auto'
            })
            .fromTo(monster, 3, {
                bottom: '-300px'
            }, {
                bottom: '0px'
            }, 0)
            .fromTo(hero, 3, {
                bottom: '-100px'
            }, {
                bottom: '0px'
            }, 0)
            .set('.hero-fight-parallax.placeholder .background', {
                top: 'auto',
                bottom: 0
            })
            .set('.hero-fight-parallax.fixed', {
                display: 'none'
            });

            return fightAnimation;
        }

        function updateDuration(e) {
            durationValueCache = window.innerHeight;
        }

        function getDuration() {
            return durationValueCache;
        }

    });

});
              
            
!
999px

Console