Skip to content

Instantly share code, notes, and snippets.

@eddiemonge
Created June 11, 2013 21:27
Show Gist options
  • Save eddiemonge/5760861 to your computer and use it in GitHub Desktop.
Save eddiemonge/5760861 to your computer and use it in GitHub Desktop.
Hides/shows a fixed bar element on a page. Accepts a DOM node as ELEMENT. Y can be adjusted as needed.
(function(ele){
var win = window,
addEvt = win.addEventListener,
y = ele.offsetHeight;
ele.style.transition = "0.2s";
function hide () {
ele.style.opacity = 0.1;
}
function show () {
ele.style.opacity = 1;
}
addEvt( "scroll", function() {
if ( win.scrollY > y ) {
hide();
}
else{
show();
}
});
ele.addEventListener("mouseover", show);
ele.addEventListener("mouseout", hide);
if ( win.scrollY > y ) {
hide();
}
})(ELEMENT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment