Last active
July 5, 2016 00:53
-
-
Save danielgamage/8f4100093c3d795ab135 to your computer and use it in GitHub Desktop.
fade a background color on header over course of scrolling with jQuery
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
var scroller = function() { | |
var scrollPosition = $(window).scrollTop(); | |
if ( scrollPosition < 90 ) { | |
var bgColor = 'rgba(0, 0, 0, ' + (scrollPosition / 100) + ')'; | |
$('.navbar').css('background-color', bgColor); | |
} else { | |
$('.navbar').css('background-color', 'rgba(0, 0, 0, 0.9)'); | |
} | |
} | |
scroller(); // call on load in case someone refreshes halway down the page or hits a hash link | |
$(window).on('scroll touchmove', function(){ // scroll for mouse/trackpad, touchmove for immediate touch response | |
scroller(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment