Created
June 11, 2013 21:27
-
-
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.
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
(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