cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

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.

            
              <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>
            
          
!
            
              /**
 * 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
Loading ..................

Console