Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. (function($) {
  3. $(document).ready(function() {
  4.     var navChildren = $("#top-menu li").children();
  5.     var aArray = [];
  6.     for (var i = 0; i < navChildren.length; i++) {
  7.         var aChild = navChildren[i];
  8.         var ahrefTMP = $(aChild).attr('href');
  9.         var ahref = ahrefTMP.substring(ahrefTMP.indexOf('#'));
  10.        aArray.push(ahref);
  11.     }
  12.     $(window).scroll(function() {
  13.         var windowPos = $(window).scrollTop();
  14.         var windowHeight = $(window).height();
  15.         var docHeight = $(document).height();
  16.         for (var i = 0; i < aArray.length; i++) {
  17.             var theID = aArray[i];
  18.             var secPosition = $(theID).offset().top;
  19.             secPosition = secPosition - 135;
  20.             var divHeight = $(theID).height();
  21.             divHeight = divHeight + 90;
  22.             if (windowPos >= secPosition && windowPos < (secPosition + divHeight)) {
  23.                 $("a[href='/" + theID + "']").parent().addClass("active");
  24.             } else {
  25.                 $("a[href='/" + theID + "']").parent().removeClass("active");
  26.             }
  27.         }
  28.     });
  29.  
  30. });
  31. })(jQuery);
  32. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement