Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="test">test values go here.</div>
<div class="header">
  <h1>Header</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deleniti quisquam reiciendis veniam error nostrum assumenda hic illum ea laudantium architecto est numquam officiis iste autem magni voluptates, eaque, tenetur totam et atque illo delectus. Quae qui voluptatem, itaque, unde animi modi corrupti iure quam enim excepturi, minus ex facilis ipsum.</p></div>
<div class="tabs">Tab one | Tab two | Tab three</div>
<div class="content">
  <h1>Content</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est temporibus dolore dolor aut, eveniet nemo veritatis voluptatem obcaecati. Velit sequi dolores, delectus sapiente laboriosam? Optio blanditiis adipisci neque qui reprehenderit laudantium soluta dolorum ipsum debitis possimus magnam maxime consectetur, quis laborum sint totam eaque repellendus, natus, illo a in iusto. Maxime maiores commodi numquam quas quos laudantium dignissimos, iusto veritatis pariatur ipsa animi, recusandae explicabo consectetur! Nihil dolores veniam similique, nostrum, mollitia facere placeat rem est enim cumque ipsam reprehenderit, id harum impedit nemo. Recusandae omnis reiciendis  quidem, esse illum laudantium facilis ea unde velit nam laboriosam maiores iste, sequi numquam necessitatibus ducimus. Voluptatem animi, repellat cupiditate magni laborum libero aperiam, cum qui optio dolores non suscipit expedita? Mollitia vero, dignissimos sit minus doloribus vel cumque, aliquid sint! Voluptas modi quis consequatur, eius error deserunt corporis reprehenderit quaerat inventore consequuntur nostrum. Sit provident consectetur error quas molestias, nam tempora ipsum iure itaque aliquam. Et iste neque consectetur ex aut repellat maxime praesentium nostrum non, ipsum numquam ducimus dolor delectus quis eveniet, ut autem harum fugiat omnis, recusandae voluptate. Velit ex cum maxime, expedita vitae nostrum illum omnis quibusdam sint dolores necessitatibus in quasi atque enim commodi architecto voluptates a sit.</p></div>

            
          
!
            
              .header {
  outline: solid 1px blue;
  overflow: hidden;
}
.tabs {
  padding: 20px;
}
.content {
  outline: solid 1px green;
  max-width: 450px;
  height: 200px;
  overflow-y: scroll;
  float: left;
}
#test {
  width:200px;
  height:40px;
  outline: solid 1px red;
  position: fixed;
  right: 0;
  background-color: #fff;
  z-index: 10;
}
            
          
!
            
              //var ticking = false;
var myel = document.querySelector('.content');
var header = document.querySelector('.header');
var originalHeight = myel.offsetHeight;
var originalHeader = header.offsetHeight;
// myel.addEventListener('scroll', function(ev) {
//   console.log(ev.type);
// });
myel.addEventListener('wheel', function(e) {
  var moveBy = e.deltaY;
  if (moveBy > 0) {
    if (myel.offsetHeight < originalHeight + originalHeader) {
      e.preventDefault();
      rollTheDuck(moveBy);
    }
  } else {
    if (myel.scrollTop == 0) {
      e.preventDefault();
      rollTheDuck(moveBy);
    }
  }
});
function rollTheDuck(distance) {
  //testing purpose
  document.getElementById('test').innerText =
    myel.offsetHeight + ' <> ' + (originalHeight+originalHeader) + 
    ' (' + originalHeight + ' + ' + 
    originalHeader + ')';
  if (distance >= 0) {
    if (myel.offsetHeight + distance < originalHeight + originalHeader) {
      newHeader = header.offsetHeight - distance;
      newHeight = myel.offsetHeight + distance;
    } else {
      newHeader = 0;
      newHeight = originalHeight + originalHeader;
    }
  } else {
    if (myel.offsetHeight + distance > originalHeight) {
      newHeader = header.offsetHeight - distance;
      newHeight = myel.offsetHeight + distance;
    } else {
      newHeader = originalHeader;
      newHeight = originalHeight ;
    }
  }
  header.style.height = newHeader + "px";
  myel.style.height = newHeight + "px";
};

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console