This is from the StudioPress Altitude Pro theme. When user is at the top of the page, the site-header
is transparent. When the user scrolls the page, the ‘dark’ class is added to the site-header div
, allowing you to style the .site-header.dark
element as you see fit.
jQuery(function( $ ){
if( $( document ).scrollTop() > 0 ){
$( '.site-header' ).addClass( 'dark' );
}
// Add opacity class to site header
$( document ).on('scroll', function(){
if ( $( document ).scrollTop() > 0 ){
$( '.site-header' ).addClass( 'dark' );
} else {
$( '.site-header' ).removeClass( 'dark' );
}
});
});