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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="stage">
  <div class="panelWrap"></div>
</div>
<div id="dragBounds">
  <div id="dragControl">Drag</div>
</div>
              
            
!

CSS

              
                body {
  font-family: 'Roboto', sans-serif;
  color: white;
}
#dragControl {
  width: 100px;
  height: 60px;
  position: relative;
  background: green;
  text-align: center;
  line-height: 60px;
  position: absolute;
}
#dragControl:after {
  position: absolute;
  content: '';
  width: 4px;
  height: 8px;
  left: 49px;
  top: -8px;
  background: green;
}

#dragBounds {
  width: 400px;
  height: 60px;
  background: black;
  margin: 50px auto;
  position: relative;
}

#stage {
  width: 600px;
  margin: 10px auto;
  height: 200px;
  background: #eee;
  position: relative;
  overflow: hidden;
}
.action {
  text-align: center;
  height: 100%;
  width: 100%;
  position: absolute;
}
.panelWrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.marker {
  position: absolute;
  width: 4px;
  height: 20px;
  background-color: black;
  top: -20px;
}

              
            
!

JS

              
                console.clear();
var panelCount = 13; // change to meet your needs

var panelStop = (panelCount-1)*2; 
// how much the panel wrap moves in relation to the dragger's x position
// *2 works because the stage is twice the width of the dragger travel area (adjust accordingly)


var markerSpacing = 300/(panelCount-1); 
// 300 is the travel distance of the dragger (400 wide bounds - 100px width of the actual dragger)
// subtract 1 from the panel count so the panel wrap slides to the correct ending position as we start at 0

var dragStop = document.getElementById("dragBounds");
var snapStops = []; // empty snap array

for (i=0; i<panelCount; i++) {
  $( ".panelWrap" ).append( "<div class='action'><h1>This is panel " + (i+1) + "</h1></div>" ); //add panels
  $( "#dragBounds" ).append( "<div class='marker'></div>" ); // add markers
  var panels = $(".action");
  var markers = $(".marker"); 
  snapStops.push(i*markerSpacing); // fill the snap array
  var newColor = bgColor(); // random color
  TweenMax.set(panels[i], {right: i*100+"%", backgroundColor:newColor }); // position the panels
  TweenMax.set(markers[i], {left: i*markerSpacing+49, backgroundColor:newColor }); // markers start @ 50px - 1px to compensate for their width
}

Draggable.create("#dragControl", {
  type: "x",
  throwProps: true,
  bounds: dragStop,
  edgeResistance: 1,
  snap: snapStops,
  onDrag: makeEmMove,
  onThrowUpdate: makeEmMove
});

function makeEmMove() {
  TweenMax.set(".panelWrap", { x: this.x * panelStop});
}

// just random colors for the panels
function bgColor() {
    var x = Math.floor(Math.random() * 256);
    var y = Math.floor(Math.random() * 256);
    var z = Math.floor(Math.random() * 256);
    return "rgb(" + x + "," + y + "," + z + ")";
    
}

              
            
!
999px

Console