Last active
December 16, 2015 19:09
-
-
Save cherihung/5482802 to your computer and use it in GitHub Desktop.
Sample code for adding/removing css class names according to a user's scrolling position on the page. example result is to change the background color of navigational items.
$j for use with jQuery.noConflict();
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
$j(window).scroll(function(){ | |
$navp = $j('#mm-nav'); | |
$nav = $j('#mm-nav li a'); | |
$navp = $j('#mm-nav'); | |
$nav = $j('#mm-nav li a'); | |
for(var i=1; i<8; i++) { | |
var os = i === 7 ? 190 : 90; | |
if($j(this).scrollTop() >= $j('.p'+i).offset().top - os) { | |
$nav.removeClass("sel"); | |
$j('#mm-nav #a'+i ).addClass("sel"); | |
} | |
} | |
if ($j(this).scrollTop() > 250 && $navp.css('position') != 'fixed'){ | |
$navp.addClass("fixedhead"); | |
} else if ($j(this).scrollTop() < 250 && $navp.css('position') == 'fixed'){ | |
$navp.removeClass("fixedhead"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment