javascript - jQuery Waypoints sticky nav when scrolling up via a click is 1px off -


i'm close tearing hair out waypoints. first of all, i'm far being experienced in javascript. i'm using waypoints 1) fix nav top of screen @ point (this works fine) , 2), highlight nav items when sections reached. works except when click nav item requires waypoint direction up, e.g. click "exceptional value" , "destinations." you'll notice waypoint seems pixel off , "exceptional value" still highlighted. if scroll pixel, "destinations" highlights. way replicate behavior... clicking nav items scroll down works fine. here js: http://jsfiddle.net/treud/. here site it's implemented on: http://ifb.thepinkrobot.com/. help... it's appreciated.

        <!-- waypoints -->     <script type="text/javascript">     $(document).ready(function(){       $('.nav-container').waypoint(function(direction) {         $('nav#main').toggleclass('sticky', direction === 'down');         });     });     </script>      <script type="text/javascript">     var sections = $("section");         var navigation_links = $("nav a");          sections.waypoint({             handler: function(event, direction) {                  var active_section;                 active_section = $(this);                 if (direction === "down") active_section = active_section.prev();                  var active_link = $('nav a[href="#' + active_section.attr("id") + '"]');                 navigation_links.removeclass("selected");                 active_link.addclass("selected");              },             offset: 50         })     </script>     <!-- end waypoints --> 

it's strange one. there seems 3px border on header might causing issue. if increase offset of waypoints 50 53 seems fix problem.

var sections = $("section"); var navigation_links = $("nav a");      sections.waypoint({         handler: function (event, direction) {              var active_section;             active_section = $(this);             if (direction === "down") active_section = active_section.prev();              var active_link = $('nav a[href="#' + active_section.attr("id") + '"]');             navigation_links.removeclass("selected");             active_link.addclass("selected");          },         offset: 53     }) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -