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 debounce: <span id="count1">0</span></li>
    <li>Pake debounce: <span id="count2">0</span></li>
  </ul>
</div>
            
          
!
            
              /**
 * Dikopi dari underscore.js
 */
function debounce(func, wait) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		var later = function() {
			timeout = null;
			func.apply(context, args);
		};
		var callNow = !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
};


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

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

window.addEventListener("scroll", fn1);
//jalanin fn2 setelah scroll berhenti selama 500ms
window.addEventListener("scroll", debounce(fn2, 500));

            
          
!
999px
Loading ..................

Console