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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <p>SCROLL KE ATAS / BAWAH </p>

<div style="position:fixed; width: 100%; background:#ddd">
  <p><strong>Function calls:</strong></p>  
  <ul>
    <li>Ga pake throttle: <span id="count1">0</span></li>
    <li>Pake throttle: <span id="count2">0</span></li>
  </ul>
</div>
              
            
!

CSS

              
                body{
  width:200px;
  height: 2000px;
}

              
            
!

JS

              
                /**
 * Dikopi dari underscore.js
 */
function throttle(func, wait) {
  var context, args, result;
  var timeout = null;
  var previous = 0;
  var later = function() {
    previous = 0;
    timeout = null;
    result = func.apply(context, args);
    if (!timeout) context = args = null;
  };
  return function() {
    var now = Date.now();
    if (!previous) previous = now;
    var remaining = wait - (now - previous);
    context = this;
    args = arguments;
    if (remaining <= 0 || remaining > wait) {
      if (timeout) {
        clearTimeout(timeout);
        timeout = null;
      }
      previous = now;
      result = func.apply(context, args);
      if (!timeout) context = args = null;
    } else if (!timeout) {
      timeout = setTimeout(later, remaining);
    }
    return result;
  };
}

var count1 = 0;
var msg1 = document.getElementById("count1");
var fn1 = function() {
  msg1.innerText = 'call count: '+ count1++ + ", scrollY: " + this.scrollY;
};

var count2 = 0;
var msg2 = document.getElementById("count2");
var fn2 = function() {
  msg2.innerText = 'call count: '+count2++ + ", scrollY: " + this.scrollY;
};

window.addEventListener("scroll", fn1);
window.addEventListener("scroll", throttle(fn2, 200));

              
            
!
999px

Console