Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- var highlighted = null, // Keep track of previously selected
- $menuItems = $('#menu a'); // Grab all menu items once
- // Which items at which points
- var breakpoints = {
- '#menu-item-25': 590,
- '#menu-item-26': 1380,
- '#menu-item-22': 2545,
- '#menu-item-23': 2969,
- '#menu-item-24': 99999
- };
- $(window).scroll(function() {
- var scroll = $(window).scrollTop(),
- selected = '#menu-item-24'; // default
- // Loop through breakpoints to find the current one that should be selected
- for (id in breakpoints) {
- if (scroll <= breakpoints[id]) {
- selected = id;
- break;
- }
- }
- // If the right one is already highlighted, do nothing
- if (highlighted == id) {
- return;
- }
- // Remove all
- $menuItems.removeClass('blue');
- // Add it to the one you need
- $(id).addClass('blue');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement