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 class="tlContainer clearfix">
  <div class="tlContent">
    <div class="tlBox red">
      <p>1</p>
    </div>
    <div class="tlBox green">
      <p>2</p>
    </div>
    <div class="tlBox blue">
      <p>3</p>
    </div>
    <div class="tlBox red">
      <p>4</p>
    </div>
    <div class="tlBox green">
      <p>5</p>
    </div>
    <div class="tlBox blue">
      <p>6</p>
    </div>
    <div class="tlBox red">
      <p>7</p>
    </div>
    <div class="tlBox green">
      <p>8</p>
    </div>
    <div class="tlBox blue">
      <p>9</p>
    </div>
  </div>
</div>
<div id="sliderText">Use the slider to scroll through colored panels</div>
<div id="slider"></div>

<div id="debug"></div>
              
            
!

CSS

              
                *{
  box-sizing: border-box;
}

html,
body {
  font-family: sans-serif;
  margin: 0;
  color: #888;
  background: #2B2C2D;
  /*overflow: hidden;*/
}

.tlContainer {
  width: 90%;
  height: 260px;
  max-height: 360px;
  background-color: white;
  position: relative;
  margin: 20px auto;
  border: 1px solid #555;
  /* toggle this on/off to see the start/end positions of the content div */
  overflow: hidden;
}

.tlContent {
/*   holder of the boxes */
  /* \\ we don't need to to set a width \\  */
  /*width: 12000px;*/
  
  height: 100%;
  
  /* \\ Uneccesary for relative position unless not 0 \\  */
  /*top: 0;
  left: 0;*/
  
  position: relative;
  /*border: 1px solid red;*/
  
  /* \\ This is what will allow  the contents to not wrap
     \\ so our container can grow horizontally 
  */
  white-space: nowrap;
  
  /* \\ Deals with spaces in the markup so they are not 
     \\ rendered as 4px gaps 
  */
  font-size: 0;
}

.tlBox {
  /* Since the container's font-size is 0, let's reset here */
  font-size: 13pt;
  
  width: calc(33.3%);
  height: 100%;
  margin: 0 5px 0 0;
  
  /* \\ Floating has a  lot of inherent issues
     \\ we'll go with inline-block' */
  /*float: left;*/
  display: inline-block;
  vertical-align: top;
  
  text-align: center;
  color: #fff;
  /*display: block;*/
  border: 2px solid blue;
  
  /* \\ Because the parent is set to nowrap, this inherits that
     \\ we want the content of the tile to behave "normally" */
  white-space: normal;
  
}

.red {
  background-color: red;
}

.green {
  background-color: green;
}

.blue {
  background-color: blue;
}

/* #ctrl_slider {
  width: 400px;
  margin: 10px auto;
} */

#slider {
/*   position:relative; */
  width: 824px;
  height:10px;
  margin: 10px auto;
  background: rgba(80,80,80,0.5);
  border:1px solid rgba(102,102,102,0.5);
}

#sliderText {
  text-align:center;
}

#debug div{
  height: 50px;
  background-color: #CCC;
  margin: 15px;
}
              
            
!

JS

              
                // get width of boxes, and multiply by how many to set width of sliding container div.
var _boxesVis = 3;


// Include the 5px margin if the CSS is using one.
var _boxwidth = $('.tlBox').first().width() + 5 + 4; // +4 is because of the order width
var _boxCount = $('.tlBox').length;
var _tlInnerWidth = _boxwidth * _boxCount;

/* // We get the width of the masking div
*/
var _tlContainerWidth = $('.tlContainer').width();
/* // We now set the animate 'x' distance to be the width of all the tiles minus 
   // the width of the masking window so we don't animate into empty space
*/
var _animateWidth = (_tlInnerWidth - _tlContainerWidth) + 5; // +5 is to note animate to the last right margin

/* // We don't need to  calculate this, CSS  
   // rules allow it to be set itself
*/
// set the container div width to the calculated _tlInnerWidth
//TweenLite.set(".tlContent", {width: _tlInnerWidth});

// Set an array of snapto points
var snapPoints = [];
var snapPointsCount =  _boxCount-_boxesVis;
var snapInc = _boxwidth/_animateWidth;
console.log('snapInc: '+snapInc);
for(i=0;i<=snapPointsCount;i++){ 
  snapPoints[i]= snapInc*i;
}
console.log(snapPoints);

//responsive timeline animation.
//values recorded once, nothing changes on resize
// var tl = new TimelineMax({repeat:-1, yoyo:true, repeatDelay:1}) 

var tl = new TimelineMax() 
// make the timeline duration equal to the number of boxes (in seconds)

/* // Instead of animating a percentage, we animate the calculated 
   // width above , `_animateWidth`
*/
tl.to(".tlContent", _boxCount, {x:-(_animateWidth), force3D:true, ease: Power0.easeNone});


/* // I modified nothing below
*/
tl.pause();
// tl.play(); 

varctrl = $("#slider"),
ctrlValue = {value:0}; 

varctrl.slider({
  animate: "fast",
  range: false,
  min: 0,
  max: 100,
  step:.1,
  start:function() {
    tl.pause();
  },
  slide: function ( event, ui ) {
    tl.progress( ui.value / 100 );
    console.log( ui.value/100 );
  },
  stop: function() {
    var _curProgress = tl.progress();
    var snapTo =  closest( snapPoints , _curProgress );
    TweenLite.to(tl, .5, {progress:snapTo, ease: Power3.easeOut});
    $("#slider").slider( 'value' , snapTo*100 );
  }
});

//tl.eventCallback("onUpdate", function() {
  //trlValue.value = tl.progress() * 100;
  //varctrl.slider(ctrlValue);
//});


/* // Function to pass in an integer and retrun the closest value from set
*/

/**
* Returns the closest number from a sorted array.
**/
function closest(arr, target) {
    if (!(arr) || arr.length == 0)
        return null;
    if (arr.length == 1)
        return i[0];

    for (var i=1; i<arr.length; i++) {
        // As soon as a number bigger than target is found, return the previous or current
        // number depending on which has smaller difference to the target.
        if (arr[i] > target) {
            var p = arr[i-1];
            var c = arr[i]
            return Math.abs( p-target ) < Math.abs( c-target ) ? p : c;
        }
    }
    // No number in array is bigger so return the last.
    return arr[arr.length-1];
}

/*
$('#debug').append('<div id="debug-mask">Mask</div>');
$('#debug').append('<div id="debug-animated">Animated Width</div>');
$('#debug').append('<div id="debug-tile">Tile</div>');
$('#debug').append('<div id="debug-snapPoints">Snap Increment</div>');

$('#debug-mask').width(_tlContainerWidth);
$('#debug-animated').width(_animateWidth);
$('#debug-tile').width(_boxwidth);
$('#debug-snapPoints').width( (_boxwidth/_animateWidth)*_animateWidth );
*/
              
            
!
999px

Console