Created
February 19, 2020 21:45
-
-
Save lilumi/bc55683bf192fa4bd561060d879d07c3 to your computer and use it in GitHub Desktop.
Scroll arrow hides on scroll (optimized for passive listeners)
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
//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