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 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.

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

<div style="position:fixed; width: 100%; background:#ddd">
  <p><strong>Function calls:</strong></p>  
    <li>Ga pake debounce: <span id="count1">0</span></li>
    <li>Pake debounce: <span id="count2">0</span></li>
 * 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;
		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));

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