Created
March 22, 2015 00:17
-
-
Save bhalash/41dc13bfcf55d675a854 to your computer and use it in GitHub Desktop.
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 nav = { | |
id: 'nav#top-menu', | |
anchor: 'nav#top-menu li', | |
content: '#content', | |
shadow: 'nav-box-shadow', | |
boxShadow: function() { | |
// Set box shadow at bottom of nav menu on window scroll. | |
if ($(window).scrollTop() === 0) { | |
$(nav.id).removeClass(nav.shadow); | |
} else { | |
$(nav.id).addClass(nav.shadow); | |
} | |
}, | |
scrollOpacity: function() { | |
// Change the opacity of the top nav menu on window scroll. | |
var a = parseInt($(nav.content).css('padding-top')), | |
b = $(window).scrollTop(), | |
c = b / a; | |
// Constrain opacity between 0 and 1. | |
c = (c < 0) ? 0 : c; | |
c = (c > 1) ? 1 : c; | |
// console.log(c); | |
$(nav.id).css('background-color', 'rgba(255,255,255,' + c + ')'); | |
}, | |
invertTextColour: function() { | |
/* Graduallly invert the colour of the anchor element as the page | |
* scrolls, using RGB values. */ | |
var limits = { | |
upper: 255, | |
lower: 88 | |
}; | |
var color = limits.upper, | |
difference = limits.upper - limits.lower, | |
contentTop = parseInt($(nav.content).css('padding-top')), | |
windowPos = $(window).scrollTop(), | |
percentage = windowPos / contentTop; | |
percentage = (percentage < 0) ? 0 : percentage; | |
percentage = (percentage > 1) ? 1 : percentage; | |
color = Math.floor(limits.upper - (difference * percentage)); | |
color = (color > limits.upper) ? limits.upper : color; | |
color = (color < limits.lower) ? limits.lower : color; | |
$(nav.anchor).css('color', 'rgba(' + color + ',' + color + ',' + color + ', 1)'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment