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="app">

  <div class="app-header">
    <div class="app-header-back js-header-back hidden">
      <a href="#" class="js-back">&#8592; Back</a>
    </div>
    <div class="app-header-nav js-header-nav wide">
      <a href="#io">Io</a>
      <a href="#about">About</a>
      <a href="#blog">Blog</a>
      <a href="#contact">Contact</a>
    </div>
  </div>
  <div class="page-cover dsa"><div class="loader"></div></div>
  <div class="page-placeholder" id="page-placeholder"></div>
  
  
<script id="home-template" type="text/x-handlebars-template">
  <div class="entry">
    <h1>Hello + {{ name }}</h1>
    <h2>Tap on any image to navigate forward  <br></h2>
    <ul>
        {{#each images}}
        <li><a href="#{{href}}"><img src="{{src}}" alt="test" /></a></li>
        {{/each}}
    </ul>
  </div>
</script>

</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  background:#333;
}

h1 {
  font-size:1.1em;
  text-align:center;
  font-weight:200;
}

h2 {
  font-size:.8em;
  text-align:center;
  font-weight:200;
}
.app {
  width:100vw;
  max-width:414px;
  margin:0 auto;
  height:100vh;
  overflow:hidden;
  position:relative;
  background:#fff;
  &-header {
    background:#eee;
    width:100vw;
      max-width:414px;
  margin:0 auto;
    position:fixed;
    z-index:5;
    box-shadow:1px 1px 1px rgba(#000, .2);
    &-back {
      width:25%;
      background:#ccc;
      float:left;
      transition: width .5s;
      &.hidden {
        width:0;
        overflow:hidden;
      }
      a {
        padding:12px 0;
        display:block;
        text-align:center;
        width:100%;
        text-decoration:none;
        color:#000;
        font-size:12px;
        cursor: pointer;
        float:left;
        height:38px;
        white-space:nowrap;
        &:hover {
          background:#ccc;
          color:#fff;
        }
      }
    }
    &-nav {
      width:75%;
      float:right;
      transition: width .5s;
      &.wide {
        width:100%;
      }
      a {
        height:38px;
        width:25%;
        display:block;
        float:left;
        text-align:center;
        padding:12px 0;
        text-decoration:none;
        color:#666;
        font-size:12px;
        box-shadow:-1px 0 0 rgba(#000, .2);
        &:hover, &.active {
          background:#ccc;
          color:#fff;
        }
      }
    }
  }
  
  .page-placeholder {
    position:absolute;
    top:40px;
    width:100%;
    height:100vh;
  }
 
  .page-cover {
    position:absolute;
    top:38px; //38px is the header
    left:0;
    width:100%;
    height:calc(100vh - 38px); //38px is the header
    background:#eee;
    z-index:3;
    transform: translate3d(100%, 0px, 0px);
    box-shadow: -1px 0 2px rgba(#000, .2);
    &:before {
      content: '';
    }
    &.cover {
      animation: cover ease .3s;
		  animation-fill-mode: forwards;
    }
  }
  
  .page {
    position:absolute;
    left:0;
    width:100%;
    opacity: 0;
	  transition: opacity .3s ease;
    background:#fff;
    height:100%;
    z-index: -1;
    &:last-child {
      z-index:2!important;
    }
    &.pageFade {
      z-index: 1;
      opacity: 1;
      overflow-y: scroll!important; 
      -webkit-overflow-scrolling: touch!important;
      box-shadow: -1px 0 0 rgba(#000, .7);
	  }
    
    &.moveToLeft {
	  	z-index: 2;
  		animation: moveToLeft ease .4s;
		  animation-fill-mode: forwards;
	  }
    	&.moveToRight {
      z-index: 2;
      animation: moveToRight ease .4s;
      animation-fill-mode: forwards;
    }
    p {
      margin-top:350px;
      margin-bottom:350px;
    }
  }
}



@keyframes moveToRight {
	to { transform: translate3d(100%, 0px, 0px); }
}

@keyframes moveToLeft {
	to { transform: translate3d(-100%, 0px, 0px); }
}

@keyframes cover {
	to { transform: translate3d(0%, 0px, 0px); }
}

@keyframes pageFadeIn {
	0%   { opacity: 0; }
	100% { opacity: 1; }
}


/*
 *Not related
 */

.entry {
  ul {
    padding:0;
    margin:0 3px 0 0;
    li {
      list-style:none;
      overflow:hidden;
      width:50%;
      float:left;
      img {
        width:100%;
        display:block;
        float:left;
        margin:3px 0 0 3px;
      }
    }
  }
}

.page{
  &--something {
    ul li {
      width:33%!important;
    }
  }
  &--about {
    ul li {
      width:50%!important;
    }
  }
  &--blog {
    ul li {
      width:33%!important;
    }
  }
  &--contact {
    ul li {
      width:50%!important;
    }
  }
}

$vv_loaderSize: 20px;
.loader {
  width:$vv_loaderSize;
  height:$vv_loaderSize;
  border-radius:50%;
  position:absolute;
  top:50%;
  left:50%;
  margin-top:-$vv_loaderSize / 2;
  margin-left:-$vv_loaderSize / 2;
  &:before, &:after {
    content: '';
    display:inline-block;
    position:absolute;
    top:0;
    left:0;
    width:$vv_loaderSize;
    height:$vv_loaderSize;
    border:2px solid #eee;
    border-radius:50%;
  }
  &:after {
    bordercolor: transparent;
    border-top-color: #F18020;
    animation: vv_loaderspin .5s infinite;
  }
}


@keyframes vv_loaderspin {
    from {transform:rotate(0deg);}
    to {transform:rotate(360deg);}
}


              
            
!

JS

              
                //Define my app
var appShell = appShell || {};
appShell.images_count = 20;
appShell.cache = [];
appShell.history = [];
appShell.backButton = false;

//Every click should be prevented and made magic with it
$('.app').on('click', 'a', function(e) {
  e.preventDefault();

  //If back button is clicked
  if ($(this).hasClass('js-back')) {

    //Set a flag
    appShell.backButton = true;
    window.history.back();
  } else {

    //Navigate away, the router will know what to do
    appShell.navigate(this.hash.substr(1));
  }

});

//All views are the same
appShell.View = Backbone.View.extend({
  tagName: 'div',
  className: 'page',
  placeholder: '#page-placeholder',

  initialize: function() {
    this.render();
  },

  render: function() {
    var source = $("#home-template").html();
    var template = Handlebars.compile(source);
    var name = this.name;
    var data = {
      name: this.name,
      images: []
    };

    var imagesHref = 'home';
    switch (this.name) {
      case "home":
        imagesHref = 'io'
        break;
      case "io":
        imagesHref = 'about'
        break;
      case "about":
        imagesHref = 'blog'
        break;
      case "blog":
        imagesHref = 'contact'
        break;
      default:
        imagesHref = 'home'
    }

    _(40).times(function(n) {
      data.images.push({
        'src': 'https://source.unsplash.com/200x300/?sig=' + appShell.images_count,
        'href': imagesHref
      });
      appShell.images_count += 1
    });

    $(this.el).addClass('page--' + name).attr('id', 'page--' + name);

    var tempHtml = template(data);

    var self = this;

    appShell.backButton = false;

    $(this.el).html(tempHtml);
    $(this.el).appendTo(this.placeholder);
    $(this.el).addClass('pageFade');

    //Simulate a loading for models or data
    setTimeout(function() {
      $('.page').not('.page--' + name);
      //After a few seconds remove the cover
      setTimeout(function() {
        $('.page-cover').removeClass('cover');
      }, 200)
    }, 1000)

  }
});

//Route everything and make everything a view
appShell.router = Backbone.Router.extend({
  routes: {
    '*notFound': "renderPage"
  },

  updateBackButtonUi: function() {
    var hash = window.location.hash.replace(/^#+/i, '');

    $('.js-header-nav a').each(function() {
      if ($(this).attr('href') == '#' + hash) {
        $(this).addClass('active');
      } else {
        $(this).removeClass('active');
      }
    })

    console.log('Back button checker');

    if (appShell.history.length > 0 && hash !== '') {
      $('.js-header-back').removeClass('hidden');
      $('.js-header-nav').removeClass('wide');
    } else {

      $('.js-header-back').addClass('hidden');
      $('.js-header-nav').addClass('wide');
    }
  },

  forward: function() {

    var name = Backbone.history.fragment ? Backbone.history.fragment : 'home';

    appShell.history.push({
      name: name,
      fragment: Backbone.history.fragment
    });

    //Remove view if already here
    if (typeof appShell.cache['view' + name] !== 'undefined') {
      appShell.cache['view' + name].remove();
      delete appShell.cache['view' + name];
    }

    appShell['view' + name] = appShell.View.extend({
      name: name
    });
    appShell.cache['view' + name] = new appShell['view' + name];
  },

  backward: function() {

    var name = Backbone.history.fragment ? Backbone.history.fragment : 'home';

    //Making sure that the page was not removed by mistake, if it was, just load the view again.
    if (typeof appShell.cache['view' + name] == 'undefined') {
      this.forward();
      console.warn('Something weird');
    } else {

      $('.page').last().addClass('moveToRight').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(event) {
        var name = appShell.history[appShell.history.length - 1].name;
        appShell.backButton = false;
        appShell.cache['view' + name].remove();
        delete appShell.cache['view' + name];
        appShell.history.splice(appShell.history.length - 1);
      });

    }

  },

  renderPage: function() {
    console.log(appShell.backButton);

    this.updateBackButtonUi();

    if (appShell.backButton == true) {
      this.backward();
    } else {
      this.forward();
    }

  },
});

//Init
new appShell.router();
Backbone.history.start({
  pushState: false
});

appShell.navigate = function(location) {
  var hash = window.location.hash.replace(/^#+/i, '');
  console.log('Location: ' + location + ' and hash: ' + hash)
  if (hash !== location) {
    $('.page-cover').addClass('cover').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(event) {

      appShell.callerAnimateNavigate = true;
      window.location.hash = location;
      appShell.callerAnimateNavigate = false;

    });

  }
}
              
            
!
999px

Console