Skip to content

Instantly share code, notes, and snippets.

@michaelbourne
Created April 25, 2018 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbourne/3bf3d82aca6e50d28ea4d7b90a9d4a2c to your computer and use it in GitHub Desktop.
Save michaelbourne/3bf3d82aca6e50d28ea4d7b90a9d4a2c to your computer and use it in GitHub Desktop.
Transparent Fixed Header (Opaque on Scroll)
jQuery(document).ready(function($){
// Detect if this is a hero image page by looking for the #heroimage ID
if( $('#heroimage').length ){
// get the value of the bottom of the #heroimage element by adding the offset of that element plus its height, set it as a variable
var mainbottom = $('#heroimage').offset().top + $('#heroimage').outerHeight(true);
$(window).on('scroll',function(){
var stop = Math.round($(window).scrollTop());
// If the use has scrolled past the bottom of the hero image
if (stop > mainbottom) {
$('.x-navbar').addClass('pasthero');
} else {
// if the user has scrolled back up above the bottom of the hero image
$('.x-navbar').removeClass('pasthero');
}
});
} else {
// if no hero image present, add the opaque class right away
$('.x-navbar').addClass('pasthero');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment