Skip to content

Instantly share code, notes, and snippets.

@rcobiella
Forked from brumm/bookmarklet.js
Created February 25, 2021 11:37
Show Gist options
  • Save rcobiella/fe6bc036bdcf6e95bbcf97eec16f42a5 to your computer and use it in GitHub Desktop.
Save rcobiella/fe6bc036bdcf6e95bbcf97eec16f42a5 to your computer and use it in GitHub Desktop.
Find out which element is scrolling
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); }); }); }()
(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