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

              
                <html>

<head>
  <link href='https://fonts.googleapis.com/css?family=Oswald:400,300,700' rel='stylesheet' type='text/css'>
</head>

<body>
  <div class="content">
    <div class="wrapper">
      <div class="box box1">
        <h1 id="box1">box 1</h1>
      </div>
      <div class="box box2">
        <h1>box 2</h1>
      </div>
      <div class="box box3">
        <h1>box 3</h1>
      </div>
    </div>
  </div>
  <div class="directions">Scroll the boxes left and right.</div>
</body>

</html>
              
            
!

CSS

              
                *{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body{
  height: 100%;
  color: #fff;
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  font-size: 12px;
}

.directions {
  color: #000;
  font-size: 24px;
}

.content{
  position: relative;
  overflow: scroll;
  width: 100%;
}

.wrapper { 
  width: 2700px;
}

.box{
  width: 900px;
  height: 100px;
  float: left;
  position: relative;
}

.sticky-header {
  position: sticky !important;
  left: 0;
}

.box h1{
  padding: 0;
  position: absolute;
  transform: translate3d(0,0,0);
  float: left;
}

.box1{
  background-color: #9b59b6;
}

.box2{
  background-color: #1abc9c;
}

.box3{
  background-color: #e74c3c;
}
              
            
!

JS

              
                /* modernizr 3.2.0 (Custom Build) | MIT  https://modernizr.com/download/?-csspositionsticky-csstransforms-csstransforms3d */
!function(e,n,t){function s(e,n){return typeof e===n}function r(){var e,n,t,r,i,o,a;for(var f in C)if(C.hasOwnProperty(f)){if(e=[],n=C[f],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;t<n.options.aliases.length;t++)e.push(n.options.aliases[t].toLowerCase());for(r=s(n.fn,"function")?n.fn():n.fn,i=0;i<e.length;i++)o=e[i],a=o.split("."),1===a.length?Modernizr[a[0]]=r:(!Modernizr[a[0]]||Modernizr[a[0]]instanceof Boolean||(Modernizr[a[0]]=new Boolean(Modernizr[a[0]])),Modernizr[a[0]][a[1]]=r),y.push((r?"":"no-")+a.join("-"))}}function i(e){var n=S.className,t=Modernizr._config.classPrefix||"";if(_&&(n=n.baseVal),Modernizr._config.enableJSClass){var s=new RegExp("(^|\\s)"+t+"no-js(\\s|$)");n=n.replace(s,"$1"+t+"js$2")}Modernizr._config.enableClasses&&(n+=" "+t+e.join(" "+t),_?S.className.baseVal=n:S.className=n)}function o(){return"function"!=typeof n.createElement?n.createElement(arguments[0]):_?n.createElementNS.call(n,"http://www.w3.org/2000/svg",arguments[0]):n.createElement.apply(n,arguments)}function a(){var e=n.body;return e||(e=o(_?"svg":"body"),e.fake=!0),e}function f(e,t,s,r){var i,f,l,u,p="modernizr",d=o("div"),c=a();if(parseInt(s,10))for(;s--;)l=o("div"),l.id=r?r[s]:p+(s+1),d.appendChild(l);return i=o("style"),i.type="text/css",i.id="s"+p,(c.fake?c:d).appendChild(i),c.appendChild(d),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(n.createTextNode(e)),d.id=p,c.fake&&(c.style.background="",c.style.overflow="hidden",u=S.style.overflow,S.style.overflow="hidden",S.appendChild(c)),f=t(d,e),c.fake?(c.parentNode.removeChild(c),S.style.overflow=u,S.offsetHeight):d.parentNode.removeChild(d),!!f}function l(e,n){return!!~(""+e).indexOf(n)}function u(e){return e.replace(/([a-z])-([a-z])/g,function(e,n,t){return n+t.toUpperCase()}).replace(/^-/,"")}function p(e,n){return function(){return e.apply(n,arguments)}}function d(e,n,t){var r;for(var i in e)if(e[i]in n)return t===!1?e[i]:(r=n[e[i]],s(r,"function")?p(r,t||n):r);return!1}function c(e){return e.replace(/([A-Z])/g,function(e,n){return"-"+n.toLowerCase()}).replace(/^ms-/,"-ms-")}function m(n,s){var r=n.length;if("CSS"in e&&"supports"in e.CSS){for(;r--;)if(e.CSS.supports(c(n[r]),s))return!0;return!1}if("CSSSupportsRule"in e){for(var i=[];r--;)i.push("("+c(n[r])+":"+s+")");return i=i.join(" or "),f("@supports ("+i+") { #modernizr { position: absolute; } }",function(e){return"absolute"==getComputedStyle(e,null).position})}return t}function h(e,n,r,i){function a(){p&&(delete j.style,delete j.modElem)}if(i=s(i,"undefined")?!1:i,!s(r,"undefined")){var f=m(e,r);if(!s(f,"undefined"))return f}for(var p,d,c,h,v,g=["modernizr","tspan"];!j.style;)p=!0,j.modElem=o(g.shift()),j.style=j.modElem.style;for(c=e.length,d=0;c>d;d++)if(h=e[d],v=j.style[h],l(h,"-")&&(h=u(h)),j.style[h]!==t){if(i||s(r,"undefined"))return a(),"pfx"==n?h:!0;try{j.style[h]=r}catch(y){}if(j.style[h]!=v)return a(),"pfx"==n?h:!0}return a(),!1}function v(e,n,t,r,i){var o=e.charAt(0).toUpperCase()+e.slice(1),a=(e+" "+k.join(o+" ")+o).split(" ");return s(n,"string")||s(n,"undefined")?h(a,n,r,i):(a=(e+" "+E.join(o+" ")+o).split(" "),d(a,n,t))}function g(e,n,s){return v(e,t,t,n,s)}var y=[],C=[],w={_version:"3.2.0",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,n){var t=this;setTimeout(function(){n(t[e])},0)},addTest:function(e,n,t){C.push({name:e,fn:n,options:t})},addAsyncTest:function(e){C.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=w,Modernizr=new Modernizr;var x=w._config.usePrefixes?" -webkit- -moz- -o- -ms- ".split(" "):[];w._prefixes=x;var S=n.documentElement,_="svg"===S.nodeName.toLowerCase();Modernizr.addTest("csspositionsticky",function(){var e="position:",n="sticky",t=o("a"),s=t.style;return s.cssText=e+x.join(n+";"+e).slice(0,-e.length),-1!==s.position.indexOf(n)});var b="CSS"in e&&"supports"in e.CSS,P="supportsCSS"in e;Modernizr.addTest("supports",b||P);var z=w.testStyles=f,T="Moz O ms Webkit",k=w._config.usePrefixes?T.split(" "):[];w._cssomPrefixes=k;var E=w._config.usePrefixes?T.toLowerCase().split(" "):[];w._domPrefixes=E;var N={elem:o("modernizr")};Modernizr._q.push(function(){delete N.elem});var j={style:N.elem.style};Modernizr._q.unshift(function(){delete j.style}),w.testAllProps=v,w.testAllProps=g,Modernizr.addTest("csstransforms",function(){return-1===navigator.userAgent.indexOf("Android 2.")&&g("transform","scale(1)",!0)}),Modernizr.addTest("csstransforms3d",function(){var e=!!g("perspective","1px",!0),n=Modernizr._config.usePrefixes;if(e&&(!n||"webkitPerspective"in S.style)){var t,s="#modernizr{width:0;height:0}";Modernizr.supports?t="@supports (perspective: 1px)":(t="@media (transform-3d)",n&&(t+=",(-webkit-transform-3d)")),t+="{#modernizr{width:7px;height:18px;margin:0;padding:0;border:0}}",z(s+t,function(n){e=7===n.offsetWidth&&18===n.offsetHeight})}return e}),r(),i(y),delete w.addTest,delete w.addAsyncTest;for(var A=0;A<Modernizr._q.length;A++)Modernizr._q[A]();e.Modernizr=Modernizr}(window,document);

var FixedHeaders;

FixedHeaders = (function() {
  var $scrollContainer, _getActiveHeader, _initValues, _resetHeader, _scrollHeaders, activeHeader, hasCSS3d, hasStickyCSS, headers, init, lastLeft, oldHeader, scroll;
  lastLeft = -1;
  headers = [];
  activeHeader = {};
  oldHeader = {};
  $scrollContainer = void 0;
  hasStickyCSS = Modernizr.csspositionsticky;
  hasCSS3d = Modernizr.csstransforms3d;
  scroll = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || function(callback) {
    window.setTimeout(callback, 1000 / 60);
  };

  /**
   * _resetHeader
   *  Resets the last active header to its original position
   *  when scrolling back (to the left)
   * @param {number} offset Pixel value of the new scroll offset
   */
  _resetHeader = function(offset) {
    if (oldHeader.$element && offset < oldHeader.leftBorder) {
      if (hasStickyCSS) {
        oldHeader.$element.removeClass('sticky-header');
      } else if (hasCSS3d) {
        oldHeader.$element.css('transform', 'translate3d(0px, 0px, 0px)');
      } else {
        oldHeader.$element.css('left', '0px');
      }
    }
  };

  /**
   * _getActiveHeader
   * Sets the `activeHeader` based on the current offset. It looks
   * at the bounds set for each header and picks the active one, or
   * if the scroll is in between headers it will set `activeHeader`
   * to an empty object `{}`
   * @param {number} offset Pixel value of the new scroll offset
   */
  _getActiveHeader = function(offset) {
    _.forEach(headers, function(header) {
      if (header.rightBorder >= offset && header.leftBorder <= offset) {
        activeHeader = header;
        return false;
      } else {
        activeHeader = {};
      }
    });
  };

  /**
   * _initValues
  #
   * Creates an array of objects that contains the bounds of each header and the jQuery
   * selector to speed up checks and element queries.
  #
   * Model: {
   *  leftBorder: The left-most position where the header is fixed
   *  rightBorder: The right-most position where the header is fixed
   *  $element: The jQuery selector for the given element
   * }
  #
   * @param {object} $container jQuery selector of the scroll container
   * @param {object} $elements jQuery selector of the headers you want fixed
   */
  _initValues = function($container, $elements) {
    var $header, $parent, leftBorder, rightBorder;
    leftBorder = void 0;
    rightBorder = void 0;
    $header = void 0;
    $parent = void 0;
    $elements.each(function(i) {
      $header = $(this);
      $parent = $header.parent();
      leftBorder = $parent.position().left;
      rightBorder = leftBorder + $parent.width() - $header.width();
      headers.push({
        leftBorder: leftBorder,
        rightBorder: rightBorder,
        $element: $header
      });
    });
  };

  /**
   * _scrollHeaders
   * Animation loop that sets either of the following:
   * - `position: sticky`
   *   For browsers that have `position: sticky` we use the native
   *   sticky implementation and toggle the `.sticky-header` class outlined
   *   in `src/scss/components/_swatches--price.scss`
   * - `transform: translate3d`
   *   For browsers that can use transforms we use the hardware accelerated
   *   translate3d to move the header.
   * - `position: left`
   *   For all other browsers we will update the left position of the header
   *   as the scroll value changes.
   */
  _scrollHeaders = function() {
    var newLeft, newOffset;
    newLeft = $scrollContainer.scrollLeft();
    newOffset = 0;
    if (newLeft === lastLeft && activeHeader !== {}) {
      scroll(_scrollHeaders);
      return false;
    } else {
      lastLeft = newLeft;
    }
    _getActiveHeader(newLeft);
    if (activeHeader.$element) {
      if (hasStickyCSS && !activeHeader.$element.hasClass('sticky-header')) {
        activeHeader.$element.addClass('sticky-header');
      } else if (hasCSS3d && !hasStickyCSS) {
        newOffset = newLeft - activeHeader.leftBorder >>> 0;
        activeHeader.$element.css('transform', 'translate3d(' + newOffset + 'px, 0px, 0px)');
      } else if (!hasStickyCSS && !hasCSS3d) {
        newOffset = newLeft - activeHeader.leftBorder >>> 0;
        activeHeader.$element.css('left', newOffset + 'px');
      }
    }
    if (!_.isEqual(oldHeader, activeHeader)) {
      _resetHeader(newLeft);
      oldHeader = activeHeader;
    }
    lastLeft = newLeft;
    scroll(_scrollHeaders);
  };
  init = function($container, $elements) {
    $scrollContainer = $container;
    _initValues($container, $elements);
    _scrollHeaders();
  };
  return {
    init: init
  };
})();

FixedHeaders.init($('.content'), $('h1'));
              
            
!
999px

Console