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

              
                <body>
  <!-- main nav -->
  <nav id="topbar" role="navigation" class="valign-center">
    <div class="row collapse text-center">
      <div class="column small-4"><a href="#" data-nav="" data-show="0"><i class="fa fa-home fa-2x fa-fw"></i></a></div>
      <div class="column small-4"><a href="#" data-nav="" data-show="1"><i class="fa fa-globe fa-2x fa-fw"></i></a></div>
      <div class="column small-4"><a href="#" data-nav="" data-show="2"><i class="fa fa-navicon fa-2x fa-fw"></i></a></div>
      <div class="active-nav"><div class="active-nav__bar"></div></div>
    </div>
  </nav>
      
  <!-- show active page -->
  <main id="carousel" role="main" class="">
    <ul>
      <li class="page lefty">
        <header>
          <div class="row text-center">
            <h1>Left Page</h1>
            <p>
              swipe to change 
              <i class="fa fa-angle-right"></i>
            </p>
          </div>
        </header>
      </li>
      <li class="page centery">
        <header>
          <div class="row text-center">
            <h1>Center Page</h1>
            <p>
              <i class="fa fa-angle-left"></i>
              swipe to change 
              <i class="fa fa-angle-right"></i>
            </p>
          </div>
        </header>
      </li>
      <li class="page righty">
        <header>
          <div class="row text-center">
            <h1>Right Page</h1>
            <p>
              <i class="fa fa-angle-left"></i>
              swipe to change 
            </p>
          </div>
        </header>
      </li>
    </ul>
  </main>
  <script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/hammerjs/2.0.4/hammer.js"></script>
</body>
              
            
!

CSS

              
                @import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Roboto:900,400);

@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css);

@mixin cover {
  position: absolute;
  left: 0;
  width: 100%;
}

@mixin fill-height {
  min-height: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  position: relative;
}

@mixin antiflicker {
  -webkit-backface-visibility: hidden;
  -webkit-transform: translate3d(0,0,0) scale3d(1,1,1);
  -webkit-transform-style: preserve-3d;
}

@function white($opacity) {
  @return rgba(255,255,255,$opacity);
}

@function black($opacity) {
  @return rgba(0,0,0,$opacity);
}

// Vars
$global-duration: .3s;

// Global
$body-bg: #f0f0f0;
$body-color: #212121;
$body-font-family: 'Roboto', sans-serif;
html, body {
  @include fill-height;
  overflow: hidden;
}

body {
  background: $body-bg;
  color: $body-color;
  font-family: $body-font-family;
}

h1,h2,h3,h4,h5,h6 {
  font-family: $body-font-family;
  font-weight: 900;
}

// top bar
$topbar-height: 3em;
$topbar-bg: #05384C;
$topbar-link-color: #fff;
#topbar {
  @include cover;
  /*background-color: $topbar-bg;*/
  background: #b33a57;
background: -moz-linear-gradient(left, #b33a57 0%, #db5757 50%, #b33a57 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #b33a57), color-stop(50%, #db5757), color-stop(100%, #b33a57));
background: -webkit-linear-gradient(left, #b33a57 0%, #db5757 50%, #b33a57 100%);
background: -o-linear-gradient(left, #b33a57 0%, #db5757 50%, #b33a57 100%);
background: -ms-linear-gradient(left, #b33a57 0%, #db5757 50%, #b33a57 100%);
background: linear-gradient(to right, #b33a57 0%, #db5757 50%, #b33a57 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=$colorDark, endColorstr=$colorDark,GradientType=1 );
/* filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$colorDark', endColorstr='$colorDark',GradientType=1 ); */

  box-shadow: 0 1px 5px black(0.5);
  height: $topbar-height;
  line-height: $topbar-height;
  position: fixed;
  top: 0;
  z-index: 1;
  
  a {
    display: block;
    color: $topbar-link-color;
    //opacity: 0.9;
  }
}

// active nav
$active-nav-bar-color: #FF7B7C;
$active-nav-bar-height: 0.5em;
$active-nav-bar-width: 33.33333%;
.active-nav { 
  position: relative;
  
  &__bar {
    background-color: $active-nav-bar-color;
    top: $topbar-height - $active-nav-bar-height;
    position: absolute;
    width: $active-nav-bar-width;
    height: $active-nav-bar-height;
    transition: $global-duration ease-in-out;
  }
  
  .show-0 &__bar {
    transform: translate3d(0,0,0);
  }
  
  .show-1 &__bar {
    transform: translate3d(100%, 0, 0);
  }
  
  .show-2 &__bar {
    transform: translate3d(200%, 0, 0);
  }
}

// content carousel
#carousel {
  @include fill-height;
  @include antiflicker;
  //background: #222;
  margin: $topbar-height auto 0;
  overflow: hidden;
  
  > ul {
    box-shadow: 0 0 10px black(0.3);
    height: 100%;
    list-style: none outside;
    margin: 0;
    overflow: hidden;
    
    &.animate {
      transform: translate3d(0,0,0) scale3d(1,1,1);
      transition: $global-duration ease-in-out;
    }
    
    > li {
      height: 100%;
      float: left;
      transform: translate3d(0,0,0);
    }
  }
}

// page content
.page {
  background-position: 50%;
  background-repeat: no-repeat;
  background-size: cover;
  
  &.centery {
    background-image: url(http://i.ytimg.com/vi/CVX9Z3ZSj7g/maxresdefault.jpg);
  }
  
  &.lefty {
    background-image: url(http://kandyperaherabookings.com/images/02/04.jpg);
    left: -100%;
  }
  
  &.righty {
    background-image: url(http://buddhistinternational.org/wp-content/uploads/2015/04/Adams-Peak-Sri-Pada-Sri-Lanka.-Misty-landscape-and-Buddhist-flags-Central-Highlands-of-Sri-Lanka-Asia-travel-photography-by-travel-photographer-Matthew-Williams-Ellis2.jpg);
    left: 100%;
  }
  
  header {
    background: white(0.5);
    padding: 1em;
    text-shadow: 1px 1px 3px black(0.3);
    
    h1 {
      font-size: 3em;
    }
  }
}
              
            
!

JS

              
                // requestAnimationFrame and cancel polyfill
(function() {
  var lastTime = 0;
  var vendors = ['ms', 'moz', 'webkit', 'o'];
  for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
    window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
    window.cancelAnimationFrame =
      window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
  }
  
  if (!window.requestAnimationFrame)
    window.requestAnimationFrame = function(callback, element) {
      var currTime = new Date().getTime();
      var timeToCall = Math.max(0, 16 - (currTime - lastTime));
      var id = window.setTimeout(function() { callback(currTime + timeToCall); },
                                 timeToCall);
      lastTime = currTime + timeToCall;
      return id;
    };
  
  if (!window.cancelAnimationFrame)
    window.cancelAnimationFrame = function(id) {
      clearTimeout(id);
    };
}());

// carousel class
function Carousel(el) {
  var self = this;
  var $el = $(el);
  
  var $container = $("> ul", $el);
  var $panes = $("> ul > li", $el);
  
  var paneWidth = 0;
  var paneCount = $panes.length;
  var paneActiveIdx = 1;
  var paneActiveOffset = 0;
  
  // setup
  self.init = function() {
    $(window).on("load resize orientationchange", function () {
      setPaneDimensions();
      self.showPane(paneActiveIdx);
    });
  };
  
  // set pane index if valid
  self.showPane = function (idx, animated) {
    var index = Math.max(0, Math.min(idx, paneCount-1));
    paneActiveIdx = index;
    
    var $wrapper = $("body");
    var newCls = "show-" + index;
    $wrapper.removeClass(function (idx, cls) {
      return (cls.match(/(^|\s)show-\S+/g) || []).join(' ');
    });
    $wrapper.addClass(newCls);
    
    //var offset = ;
    paneActiveOffset = -(100 / paneCount) * paneActiveIdx;
    setContainerOffset(paneActiveOffset, animated);
  };
  
  self.throttledShowPane = _.debounce(function (idx, animated) {
    self.showPane(idx, animated);
  }, 100);
  
  // next pane
  self.next = function () {
    self.throttledShowPane(paneActiveIdx + 1, true);
  };
  
  // prev pane
  self.prev = function () {
    self.throttledShowPane(paneActiveIdx - 1, true);
  };  
  
  // set pane and container sizes
  function setPaneDimensions() {
    paneWidth = $el.width();
    _.map($panes, function (pane) {
      $(pane).width(paneWidth);
    });
    $container.width(paneWidth*paneCount);
  }
  
  // adjust container to active pane
  function setContainerOffset(percent, animated) {
    $container.removeClass("animate");
    if(animated) {
      $container.addClass("animate");
    }
    
    if (Modernizr.csstransforms3d) {
      $container.css("transform", "translate3d("+percent+"%,0,0) scale3d(1,1,1)");
    } else if (Modernizr.csstransforms) {
      $container.css("transform", "translate("+percent+"%,0)");
    } else {
      var px = ((paneWidth * paneCount) / 100) * percent;
      $container.css("left", px+"px");
    }
  }
  
  function updateContainerOffsetX(deltaX, direction) {
    var dragOffset = ((100/paneWidth) * deltaX) / paneCount;
    
    var slowRight = paneActiveIdx == 0  && direction == Hammer.DIRECTION_RIGHT;
    var slowLeft = paneActiveIdx == paneCount-1 && direction == Hammer.DIRECTION_LEFT;
    if (slowLeft || slowRight) {
        dragOffset *= .4;
    }

    setContainerOffset(dragOffset + paneActiveOffset);
  }
  
  function onPressRelease(deltaX, direction) {
    if(Math.abs(deltaX) > paneWidth / 2) {
      if(deltaX > 0) {
        self.prev();
      } else {
        self.next();
      }
    } else {
      self.throttledShowPane(paneActiveIdx, true);
    }
  }
  
  function hammerTime(ev) {
    switch(ev.type) {
      case 'panmove': 
        updateContainerOffsetX(ev.deltaX, ev.direction);
        break;
      case 'swipeleft':
        self.next();
        break;
      case 'swiperight':
        self.prev();
        break;
    }
  }
  
  var mc = new Hammer.Manager(el, {
    dragLockToAxis: true,
    dragBlockHorizontal: true
  });
  mc.add(new Hammer.Pan({ threshold: 10, pointers: 0 }));
  mc.add(new Hammer.Swipe().recognizeWith(mc.get('pan')));
  mc.on("swipeleft swiperight panstart panmove", hammerTime);
  mc.on("hammer.input", function (ev) {
    if (ev.isFinal) {
      onPressRelease(ev.deltaX, ev.direction);
    }
  });
};

var container = document.getElementById("carousel");
var c = new Carousel(container);
c.init();

// Nav click event
$('[data-nav=""]').on("click", function () { 
  var $self = $(this);
  c.throttledShowPane($self.data("show"), true);
});
              
            
!
999px

Console