-
-
Save newhope/7fb4a19bd71e0692b4dc40eb55e85c57 to your computer and use it in GitHub Desktop.
Find out which element is scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:!function() { var slice = Array.prototype.slice; function throttle(type, name, obj) { obj = obj || window; var running = false; var func = function() { if (running) { return; } running = true; requestAnimationFrame(function() { obj.dispatchEvent(new CustomEvent(name)); running = false; }); }; obj.addEventListener(type, func); } slice .call(document.querySelectorAll("*")) .filter( e => e.scrollWidth > e.offsetWidth || e.scrollHeight > e.offsetHeight ) .filter(e => { var style = window.getComputedStyle(e); return [style.overflow, style.overflowX, style.overflowY].some( e => e === "auto" || e === "scroll" ); }) .forEach(e => { var color = Math.floor(Math.random() * 16777215).toString(16); e.style.backgroundColor = "#" + color; throttle("scroll", "optimizedScroll", e); e.addEventListener("scroll", event => { console.log("%c[scroll]", "color: white; background-color:#" + color, event.target); }); }); }() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var slice = Array.prototype.slice; | |
function throttle(type, name, obj) { | |
obj = obj || window; | |
var running = false; | |
var func = function() { | |
if (running) { | |
return; | |
} | |
running = true; | |
requestAnimationFrame(function() { | |
obj.dispatchEvent(new CustomEvent(name)); | |
running = false; | |
}); | |
}; | |
obj.addEventListener(type, func); | |
} | |
slice | |
.call(document.querySelectorAll("*")) | |
.filter( | |
e => e.scrollWidth > e.offsetWidth || e.scrollHeight > e.offsetHeight | |
) | |
.filter(e => { | |
var style = window.getComputedStyle(e); | |
return [style.overflow, style.overflowX, style.overflowY].some( | |
e => e === "auto" || e === "scroll" | |
); | |
}) | |
.forEach(e => { | |
var color = Math.floor(Math.random() * 16777215).toString(16); | |
e.style.backgroundColor = "#" + color; | |
throttle("scroll", "optimizedScroll", e); | |
e.addEventListener("scroll", event => { | |
console.log("%c[scroll]", "color: white; background-color:#" + color, event.target); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment