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 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="swipegory">
  <nav>
    <ul>
      <li><a href="#item1">About</a></li>
      <li><a href="#item2">Featured</a></li>
      <li><a href="#item3">Recent</a></li>
      <li><a href="#item4">Popular</a></li>
      <li><a href="#item5">Lorem</a></li>
      <li><a href="#item6">Ipsum</a></li>
      <li><a href="#item7">Dolor</a></li>
    </ul>
  </nav>
  <ul class="panes">
    <li>
      <h1>Swipegory</h1>
      <p>Swipegory is a swipable content slider often used to swipe between categories in mobile apps.</p>
      <p><img src="https://lh4.ggpht.com/LxWCQV9V0yWTDhIgcJAVY6tj0kr5DjFdpZobusVzBYMCkuxhPu11pO-tdbhhavTqVxHm=h900"  /></p>
    </li>
    <li><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p></li>
    <li><h1>Lorem</h1><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p></li>
    <li><h1>Lorem</h1><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p></li>
    <li><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p></li>
    <li><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</li>
    <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.</p></li>
  </ul>
</div>
<p class="footer">
  Inspired by Zedge on Android
</p>
              
            
!

CSS

              
                @height: 70px;

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  padding: 0;
  background: #eee;
  font: 16px/2em 'Montserrat', sans-serif;
}

img {
  max-width: 150px;
  heigth: auto;
  display: block;
  margin: 0 auto;
}

h1 {
  text-align: center;
  font-size: 26px;
  margin: 10px 0 20px 0;
}

p {
  margin: 0 0 20px 0;
  &.footer {
    font-size: 12px;
    text-align: center;
  }
}

.swipegory {
  position: relative;
  max-width: 320px;
  height: 480px;
  margin: 0 auto;
  background: #fff; 
  padding-top: @height;
  overflow: hidden;
  transition: 1s height;
  transform: translate3d(0,0,0);
  margin-bottom: 5px;
  
  nav {
    ul {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: @height;
      background: #333;
    }
    li {
      position: absolute;
      top: 0;
      left: 100%;
      display: block;
      transition: 1s all;
      transform: translate3d(0,0,0);
      line-height: @height;  
      height: @height;  
      font-size: 12px;
      text-transform: uppercase;
      &.prev {
        left: 0;
      }
      &.cur {
        left: 50%;
        a {
          color: #fff;
          &:after {
            opacity: 1;
            transform: translate3d(0,0,0);
          }
        }        
      }
      &.next {
        left: 100%;
      }
      &.before {
        left: 0;
      }
      &.after {
        left: 100%;
      }
      a {
        position: relative;
        color: #999;
        text-decoration: none;
        padding: 0 20px; 
        height: @height;  
        line-height: @height;
        display: block;
        overflow: hidden;
        transition: 1s color;
        &:after {
          content: ' ';
          position: absolute;
          bottom: 0;
          left: 0;
          background: cyan;
          width: 100%;
          height: 3px;          
          opacity: 0;
          transition: 1s all;
          transform: translate3d(0,3px,0);
        }
      }
      
    }
  }
  ul.panes {
    position: absolute;
    width: 100%;
    height: 100%;
    cursor: move;
    li {
      position: absolute;
      top: 0;
      left: 100%;
      width: 100%;
      padding: 20px 20px 0 20px;
      transition: 1s all;
      transform: translate3d(0,0,0);
            
      &.prev {
        transform: translate3d(-200%,0,0);
      }
      &.cur {
        transform: translate3d(-100%,0,0);
      }
      &.next {
        transform: translate3d(0,0,0);
      }
      &.before {
        transform: translate3d(-200%,0,0);
      }
      &.after {
        transform: translate3d(0,0,0);
      }
    }
  }
}

@media all and (min-width: 320px) {
  body {
    padding: 20px 0;
  }
}

              
            
!

JS

              
                var autoAdjustHeight = true;

// update on click
$('nav a').on('mousedown', function(e){
  e.preventDefault();
  var goTo = $(this).parent().index();  
  swipegoryUpdate(goTo);
});

// update on touch
$("ul.panes").swipe({
  swipeStatus:function(event, phase, direction, distance, duration, fingerCount) {    
    var translateString = 'translate3d(0px, 0px, 0px)';
    var transitionDuration = $('nav li.cur').css('transitionDuration');
    var speed = transitionDuration;    
    
    if(phase == 'move') {
      speed = '0ms';      
      if(direction == 'left') {
        translateString = 'translate3d(-' + distance + 'px, 0px, 0px)';
        $('.panes li.cur').css('marginLeft', '-'+ distance +'px');
      }
      else if(direction == 'right') {
        translateString = 'translate3d(' + distance + 'px, 0px, 0px)';
        $('.panes li.cur').css('marginLeft', distance +'px');
      }
      $('nav li.cur').css({ 
        transitionDuration: speed,
        transform: translateString
      });
      
    }
    else if (phase == 'end') {
      // reset transform3D    
      var marginLeft = $('nav li.cur').css('marginLeft');
      $('nav li.cur').attr('style', '').css('marginLeft', marginLeft);
      $('.panes li.cur').attr('style', '');
    }
  },
  swipeLeft:function(event, direction, distance, duration, fingerCount) {
    //This only fires when the user swipes left
    var goTo = $('nav li.cur').index();
    goTo++;
    swipegoryUpdate(goTo); 
  },
  swipeRight:function(event, direction, distance, duration, fingerCount) {
    //This only fires when the user swipes left
    var goTo = $('nav li.cur').index();
    goTo--;
    swipegoryUpdate(goTo); 
  },
  threshold: 50,
  triggerOnTouchEnd: false,
  allowPageScroll: "vertical",
  excludedElements: "button, input, select, textarea, .noSwipe"
});

// update on load
$(window).load(function() {
  swipegoryUpdate(0);  
});

function swipegoryUpdate(goTo) {
  var listItems = $('nav li');
  var panes = $('.panes');
  var prev = goTo - 1;
  var next = goTo + 1;  
  if(goTo >= 0 && goTo < listItems.length) {   
    listItems.removeClass('prev').removeClass('cur').removeClass('next').removeClass('before').removeClass('after');
    $('li', panes).removeClass('prev').removeClass('cur').removeClass('next').removeClass('before').removeClass('after');

    listItems.each(function(i) {
      var li = $(this);
      var pane = $('li:eq('+i+')', panes);
      
      li.attr('style', '');

      if(i == prev) {
        li.addClass('prev');
        li.css('margin-left', '0');      
        pane.addClass('prev');
      }
      else if(i == next) {
        li.addClass('next');
        li.css('margin-left', '-' + li.outerWidth() + 'px');
        pane.addClass('next');
      }
      else if(i < goTo) {
        li.addClass('before');
        li.css('margin-left', '-' + li.outerWidth() + 'px');
        pane.addClass('before');
      }
      else if(i == goTo) {
        li.addClass('cur');
        var marginLeft = li.outerWidth() / 2;
        
        li.css('margin-left', '-' + marginLeft + 'px');
        pane.addClass('cur');

        if(autoAdjustHeight == true) {
          $('.swipegory').css('height', pane.outerHeight() + li.outerHeight());
        }

      }
      else if(i > goTo) {
        li.addClass('after');
        li.css('margin-left', '0');
        pane.addClass('after');
      }
    });    
  }
}
              
            
!
999px

Console