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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <head>
    <meta charset="UTF-8">
    <title>Page Animations</title>
    <meta name="viewport" content="width=device-width" />
    <!-- <link rel="stylesheet" href="css/page-anim.css" /> -->
</head>
<body>
    <section data-page="home" id="home" class="active">
        <h1>The Page Home</h1>
        <p>Some content on the home page.</p>
        <p><a href="#other" data-role="link">GO TO OTHER</a></p>
    </section>
    <section data-page="other" id="other">
        <h1>The Page Other</h1>
        <p>Some content on the other page.</p>
        <p><a href="#home" data-role="link">GO TO HOME</a></p>
    </section>
    <!-- <script src="js/page-anim.js"></script> -->
</body>
            
          
!

CSS

            
              /****
page-anim.css
****/
*{
    padding:0;
    margin: 0;
    box-sizing: border-box;
}
:root {
    font-size: calc(1vw + 1vh + .5vmin);
}
body {
    font: 1rem/1.6 sans-serif;
    width:100%;
    min-height: 100vh;
    overflow: hidden;
}
[data-page]{
    position:fixed; /* or absolute if the content exceeds the height of the page */
    width: 100%;
    min-height: 100vh;
    transform: translate3d(100%, 0, 0);
    opacity: 0;
    transition: transform 0.5s ease-in, opacity 0.5s ease-in; 
    /*
    left: 100%;
    transition: left 1.0s ease-in; 
    */
    z-index: 10;
}
[data-page="home"]{
    background-color: hsl(90, 70%, 20%);
    color: hsl(90, 90%, 90%);
}
[data-page="other"]{
    background-color: hsl(270, 70%, 20%);
    color: hsl(270, 90%, 90%);
}
[data-page].active{
    transform: translate3d(0, 0, 0);
    opacity: 1;
    /**
    left: 0;
    **/
    z-index: 100;
}
[data-role="link"]{
    color: white;
}
section h1{
    padding: 1rem;
    text-align: center;
}
section p{
    padding: 1rem 2rem;
}
            
          
!

JS

            
              //page-anim.js
//iife version of basic animation and navigation (without History API)
var app = (function(){
    let pages = [];
    let links = [];
    
    document.addEventListener("DOMContentLoaded", function(){
        pages = document.querySelectorAll('[data-page]');
        links = document.querySelectorAll('[data-role="link"]');
        //pages[0].className = "active";  - already done in the HTML
        [].forEach.call(links, function(link){
            link.addEventListener("click", navigate)
        });
    });
    
    function navigate(ev){
        ev.preventDefault();
        let id = ev.currentTarget.href.split("#")[1];
        [].forEach.call(pages, function(page){
           if(page.id ===id){
               page.classList.add('active');
           }else{
               page.classList.remove('active');
           } 
        });
        return false;
    }
    
    return {
        pages,
        links,
        xhr: ajax
    }
})();

//the navigate method is private inside our iife
//the variables pages and links are public and can be accessed as app.pages or app.links


            
          
!
999px

Console