Created
April 25, 2018 22:01
-
-
Save michaelbourne/3bf3d82aca6e50d28ea4d7b90a9d4a2c to your computer and use it in GitHub Desktop.
Transparent Fixed Header (Opaque on Scroll)
This file contains hidden or 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
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