Skip to content

Instantly share code, notes, and snippets.

@shlomohass
Forked from johnnyopao/HiddenFixedHeaderMenu.js
Last active August 29, 2015 14:20
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 shlomohass/1333908e461e16602cf5 to your computer and use it in GitHub Desktop.
Save shlomohass/1333908e461e16602cf5 to your computer and use it in GitHub Desktop.
<script>
//Hidden Fixed header v1.1
//Replace ID below with your box ID
var boxToFix = '#lp-pom-box-88';
//Set the number of pixels to scroll before showing the header
var scrollPositionToShowHeader = 50;
var boxParent = $(boxToFix).parent();
var boxClone = $(boxToFix).clone();
$(boxClone).appendTo(boxParent).css({"position":"fixed", "left":"0", "top":"0", "width":"100%", "z-index":"899"}).children().remove();
$(boxToFix).css({"position":"fixed", "left":"auto", "top":"0px", "width":"100%", "z-index":"999", "border-style":"none none none none", "border-width":"0px", "background":"none"});
showOrHideHeader();
function showOrHideHeader() {
var currentPositionFromTop = $(window).scrollTop();
if (currentPositionFromTop > scrollPositionToShowHeader) {
$(boxToFix).show();
$(boxClone).show();
} else {
$(boxToFix).hide();
$(boxClone).hide();
}
}
$(window).scroll(function() {
showOrHideHeader();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment