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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <div id="menu">
  <div id="top"> <!-- "viewport" for menu -->
    <div class="swipecontainer"> <!-- Moving part for menu items -->
      <ul class="swipemenu">
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
        <li>Four</li>
        <li>Five</li>
        <li>Very long Six</li>
        <li>Seven</li>
        <li>Eight</li>
      </ul>
      <div id="menumarker"></div>
    </div>
  </div>
  <div id="viewport"> <!-- "viewport" for content -->
    <div id="content">
      <div class="box one">
        <h2>#1</h2>
        <p>Hello there!<br/>
          This pen shows how to recreate Android's "sliding tabs" (from the Play store for example) in pure Javascript and HTML.</p>
      </div>
      <div class="box two">
        <h2>#2</h2>
        <p>Hello there! this is number two</p>
        <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
      </div>
      <div class="box three">
        <h2>#3</h2>
        <p>Hello there! this is number three, an example form:</p>
            <form action="#" method="post">
        <div>
             <label for="name">Text Input:</label>
             <input type="text" name="name" id="name" value="" tabindex="1" />
        </div>
        <div>
             <h4>Radio Button Choice</h4>

             <label for="radio-choice-1">Choice 1</label>
             <input type="radio" name="radio-choice-1" id="radio-choice-1" tabindex="2" value="choice-1" />

         <label for="radio-choice-2">Choice 2</label>
             <input type="radio" name="radio-choice-2" id="radio-choice-2" tabindex="3" value="choice-2" />
        </div>

      <div>
        <label for="select-choice">Select Dropdown Choice:</label>
        <select name="select-choice" id="select-choice">
          <option value="Choice 1">Choice 1</option>
          <option value="Choice 2">Choice 2</option>
          <option value="Choice 3">Choice 3</option>
        </select>
      </div>

      <div>
        <label for="textarea">Textarea:</label>
        <textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
      </div>

      <div>
          <label for="checkbox">Checkbox:</label>
        <input type="checkbox" name="checkbox" id="checkbox" />
        </div>

      <div>
          <input type="submit" value="Submit" />
        </div>
    </form>
      </div>
      <div class="box four">
        <h2>#4</h2>
        <ul>
         <li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.</li>
         <li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li>
         <li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li>
         <li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li>
        </ul>        
      </div>
      <div class="box ">
        <h2>#5</h2>
        <p>Hello there! this is number five</p>
      </div>
      <div class="box ">
        <h2>#6</h2>
        <p>Hello there! this is number six</p>
      </div>
      <div class="box ">
        <h2>#7</h2>
        <p>Hello there! this is number seven</p>
      </div>
      <div class="box ">
        <h2>#8</h2>
        <p>Final Destination! this is number eight</p>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                #menu {
  width:auto;
  height:100%;
  overflow:hidden;
  background-color:#eee;
}
#top {
  height:75px;
  border-bottom:5px solid #eee;
  background-color:white;
  overflow:hidden;
  position:relative;
}

div.swipecontainer {
  position:absolute;
  top:0;
  left:0;
  height:100%;
}
ul.swipemenu {
  list-style:none;
  display:block;
  clear:both;
  padding:0;
  margin:0;
  width:9000px;
  overflow-x:hidden;
  overflow-y:auto;
  height:100%;

}
ul.swipemenu li {
  float:left;
  display:block;
  padding:25px 50px;
  margin:0;
  cursor:pointer;
  text-align:center;
  border-right:2px solid #eee; 
}

div#menumarker {
  width:200px;
  height:5px;
  display:block;
  position:absolute;
  left:0px;
  bottom:0px;
  background-color:rgba(191, 64, 64, 1);
}
div #viewport {
  position:relative;
  width:auto;
  height:900px;
  overflow:hidden;
  
}
div#content {
  width:9000px;
  height:100%;
  overflow-x:auto;
  overflow-y:hidden;
  position:absolute;
  top:0px;
  left:0px;
}
#content .box {
  height:100%;
  float:left;
  padding:20px;
  margin:0;
  margin-right:100px;
  box-shadow:0px 0px 10px #ccc;
  background:white;
}

/*optional styling thingies */
body {
  font-family:"Open Sans",sans-serif;
}
p,li,input,label,select {
  font-size:14px;
  line-height:1.5em;  
}
              
            
!

JS

              
                var viewPort = document.getElementById('viewport');

//global variables 
boxes = $(".box");
viewPortW = $(viewPort).outerWidth(true);
boxes.width(viewPortW-40);

boxW = $(boxes[0]).outerWidth(true);
menuItems = $(".swipemenu li").length;
menuItemW = $(".swipemenu li:first").outerWidth(true);
$("#menumarker").width(menuItemW);
activeIndex = 0;

//OPTIONS
animationOptions = {duration: 500, easing:"easeInOutCubic"}; //menu animations
swipeTreshold = 150; //activates swipe

//Actually Changing tabs
function setActive(i) {
  current = $(boxes[i]);
  current.addClass("active");
  var marker = $("#menumarker");
  var scrollBoundaryRight = viewPortW*0.6; //fraction of real viewport
  var scrollBoundaryLeft = viewPortW*0.4;
  
  //check if menumarker goes out of screen (on either side)
  var dx=null;
  if((marker.offset().left+marker.width()) > scrollBoundaryRight && (i>activeIndex)) {
    dx =  (marker.offset().left+marker.width()) - scrollBoundaryRight;
  } 
  if (marker.offset().left < scrollBoundaryLeft && (i<activeIndex)) {
    dx =  marker.offset().left - scrollBoundaryLeft;
  }
  if(dx) { $(".swipecontainer").animate({left: "-="+dx+"px" }, animationOptions); }
  
  //Change content
  $("#content").animate({left: -(boxW*i) }, animationOptions); 
  
  //Update the colored box in the menu
  var menuItem = $(".swipemenu li:eq("+i+")");
  marker.animate({ left:   menuItem.position().left,
                  width:   menuItem.outerWidth()
                 }, animationOptions); 
  
  activeIndex = i;
}

//inital setting
setActive(0);

//EVENT listeners
//---------------
$(".swipemenu li").on("click",function(e){
  var i = $(".swipemenu li").index($(e.currentTarget));
  setActive(i);
});

//Hammer JS for all touch related magic
var mc = new Hammer(viewPort);
mc.add(new Hammer.Pan({ threshold: 0, pointers: 0, direction: Hammer.DIRECTION_HORIZONTAL }));

startX = $("#content").position().left;
//listen to events
mc.on("panstart panmove pancancel panend", function(ev){
  if(ev.type=="panstart"){
    startX = $("#content").position().left;
  } 
  //update content position during touch event
  else if(ev.type=="panmove") { 
    $("#content").css('left',startX + ev.deltaX+'px');
    $("#menumarker").css('left',(menuItemW*activeIndex) + (-0.2*ev.deltaX)+'px');  
  } 
  else if(ev.type=="panend" || ev.type=="pancancel") {
    if(ev.deltaX > swipeTreshold && activeIndex > 0) { //bigger than treshold, so next slide
      setActive(activeIndex-1); console.log("previous!");
    }
    else if(ev.deltaX < swipeTreshold && activeIndex < menuItems-1 ) {
      setActive(activeIndex+1); console.log("next!");
    }
    else {
      //bounce effect
      $("#content").animate({left: startX }, animationOptions); 
      $("#menumarker").animate({left: (menuItemW*activeIndex)}, animationOptions); 
    }
  }  
});
              
            
!
999px
Learning 3D transforms in CSS requires a little perspective.

Console