Skip to content

Instantly share code, notes, and snippets.

@lilumi
Created February 19, 2020 21:45
Show Gist options
  • Save lilumi/bc55683bf192fa4bd561060d879d07c3 to your computer and use it in GitHub Desktop.
Save lilumi/bc55683bf192fa4bd561060d879d07c3 to your computer and use it in GitHub Desktop.
Scroll arrow hides on scroll (optimized for passive listeners)
//scroll arrow hides on scroll
function hideOnScroll() {
var scroll_el = document.getElementById('scroll');
if ( document.getElementById('app').scrollTop > 20 ) {
scroll_el.style.display = "none";
} else {
scroll_el.style.display = "block";
}
}
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}
if (document.getElementById('scroll')) {
document.getElementById('app').addEventListener('scroll', hideOnScroll, supportsPassive ? { passive: true } : false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment