cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              
<h3>Try scrolling in the 2 boxes...</h3>
<div>
  <div class="wrapper normal">
    <div class="desc">Normal scroll</div>
    <div class="content">
      <div class="inner"></div>
    </div>
    <span class="count">0</span>
  </div>
  <div class="wrapper throttled">
    <div class="desc">Throttled scroll</div>
    <div class="content">
      <div class="inner"></div>
    </div>
    <span class="count">0</span>
  </div>
</div>
            
          
!
            
              .wrapper {
  width: 200px;
  height: 200px;
  float: left;
  border: 1px solid #ddd;
  overflow: auto;
  position: relative;
  
  &:first-child {
    margin-right: 40px;
  }
  
  .content {
    height: 100%;
    width: 100%;
    overflow: auto;
    
    .inner {
      height: 6000px;
    }
  }
  
  .desc {
    position: absolute;
  }
  
  .count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

            
          
!
            
              var normalCount = 0
var throttledCount = 0

$('.normal .content').on('scroll', function(e) {
  $('.normal .count').text(++normalCount)
})


$('.throttled .content').on('scroll', throttle(function(e) {
  $('.throttled .count').text(++throttledCount)
}, 250))

$(document).on('mouseleave', function(e) {
  normalCount = 0
  throttledCount = 0
  $('.count').text(0)
})


function throttle(fn, threshhold) {
  var last
  var timer
  threshhold || (threshhold = 250)

  return function () {
    var context = this
    var args = arguments

    var now = +new Date()

    if (last && now < last + threshhold) {
      clearTimeout(timer)
      timer = setTimeout(function () {
        last = now
        fn.apply(context, args)
      }, threshhold)
    } else {
      last = now
      fn.apply(context, args)
    }
  }
}

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console