Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Created October 23, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lewiscowles1986/90833511b8d3db6c81be7eb503bab787 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/90833511b8d3db6c81be7eb503bab787 to your computer and use it in GitHub Desktop.
Hide / show element depending on scroll position
(function(target, threshold, elem) {
listener = () => {
if (target.scrollY > threshold) {
elem.style.opacity = 1;
} else {
elem.style.opacity = 0;
}
};
target.addEventListener(
'scroll',
listener,
false
);
})(window, 300, document.querySelector('#rightCol'))
@Lewiscowles1986
Copy link
Author

for facebook (where I tested this) the below CSS should be injected (inspect element put inside a <style></style> tag

#rightCol {
    transition: opacity 1s;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment