title: Changing Active Menu Item on Scroll
body: <p>I'm working with the suggestion from this post <a href="https://stackoverflow.com/questions/9979827/change-active-menu-item-on-page-scroll">Change Active Menu Item on Page Scroll?</a> but can't seem to get it working.</p>
  
  <p>Here is my page: <a href="http://terminalcitymarketing.com/drafts/liftx/flexslider-2/about-us" rel="nofollow noreferrer">http://terminalcitymarketing.com/drafts/liftx/flexslider-2/about-us</a></p>
  
  <p>Here's the HTML:</p>
  
  <pre><code>&lt;nav class="side-nav"&gt;                                          
  
  
      &lt;ul class="menu"&gt;
          &lt;li class="page_item"&gt;&lt;span style="padding-left:10px;"&gt;&lt;strong&gt;Jump To Section&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;
          &lt;li class="page_item current_page_item"&gt;&lt;a href="#lift-x"&gt;&lt;span&gt;Lift-X&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="page_item"&gt;&lt;a href="#team"&gt;&lt;span&gt;Our Team&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="page_item"&gt;&lt;a href="#community"&gt;&lt;span&gt;Lift-X in the Community&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li class="page_item"&gt;&lt;a href="#join"&gt;&lt;span&gt;Join Our Team&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;   
      &lt;/ul&gt;   
  
  &lt;/nav&gt;
  </code></pre>
  
  <p>Here is the script:</p>
  
  <pre><code>// Cache selectors
  var lastId,
      topMenu = $j(".side-nav"),
      topMenuHeight = topMenu.outerHeight()+15,
      // All list items
      menuItems = topMenu.find("a"),
      // Anchors corresponding to menu items
      scrollItems = menuItems.map(function(){
        var item = $j($j(this).attr("href"));
        if (item.length) { return item; }
      });
  
  // Bind click handler to menu items
  // so we can get a fancy scroll animation
  menuItems.click(function(e){
    var href = $j(this).attr("href"),
        offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
    $j('html, body').stop().animate({
        scrollTop: offsetTop
    }, 300);
    e.preventDefault();
  });
  
  // Bind to scroll
  $j(window).scroll(function(){
     // Get container scroll position
     var fromTop = $j(this).scrollTop()+topMenuHeight;
  
     // Get id of current scroll item
     var cur = scrollItems.map(function(){
       if ($j(this).offset().top &lt; fromTop)
         return this; 
     });
     // Get the id of the current element
     cur = cur[cur.length-1];
     var id = cur &amp;&amp; cur.length ? cur[0].id : "";
  
     if (lastId !== id) {
         lastId = id;
         // Set/remove active class 
         menuItems
           .parent().removeClass("current_page_item")
           .end().filter("[href=#"+id+"]").parent().addClass("current_page_item");
     }
  });
  </code></pre>
  
  <p>Any ideas?</p>