jquery implements fixed top positioning scrolling navigation effect code

Source: Internet
Author: User

jquery implements fixed top positioning scrolling navigation effect code, very common effect, very practical; when scrolling the scroll bar, the navigation is fixed on the top, and when scrolling to the corresponding plate, the current navigation is highlighted, and when the navigation text is clicked, smooth jumps to the corresponding plate.

$( function (){           var subNav_active = $( ".adv_active" );          var subNav_scroll =  function (target){              subNav_active.removeClass   ( "adv_active" );              target.parent().addClass( "adv_active" );              subNav_active = target.parent();          };          $( "#subNav a" ).click( function (){              subNav_scroll($( this ));              var target = $( this ).attr( "href" );              var targetScroll = $(target).offset().top - 80;              $( "html,body" ).animate({scrollTop:targetScroll},300);              return false ;          });          //页面跳转时定位          if (window.location.hash){              var targetScroll = $(window.location.hash).offset().top - 80;              $( "html,body" ).animate({scrollTop:targetScroll},300);          }          $(window).scroll( function (){              var $ this = $( this );              var targetTop = $( this ).scrollTop();              var footerTop = $( "#footer" ).offset().top;              var height = $(window).height();              if (targetTop >= 520){                  $( "#subNav" ).addClass( "fixedSubNav" );                  $( ".empty-placeholder" ).removeClass( "hidden" );              } else {                  $( "#subNav" ).removeClass( "fixedSubNav" );                  $( ".empty-placeholder" ).addClass( "hidden" );              }              if (targetTop < 750){                  subNav_scroll($( ".adv_door" ));              } else if (targetTop > 1200 && targetTop < 1640){                      subNav_scroll($( ".adv_source" ));              } else if (targetTop > 2314 && targetTop < 2734){                      subNav_scroll($( ".adv_price" ));              } else if (targetTop > 2968 && targetTop < 3268){                      subNav_scroll($( ".adv_transfer" ));              } else if (targetTop > 3327 && targetTop < 3627){                      subNav_scroll($( ".adv_payment" ));              } else if (targetTop > 3651 && targetTop < 4071){                      subNav_scroll($( ".adv_promise" ));              } else if (targetTop > 4163 && targetTop < 4473){                      subNav_scroll($( ".adv_ride" ));              } else if (targetTop > 4580){                  subNav_scroll($( ".adv_finance" ));              }          })    }());

jquery implements fixed top positioning scrolling navigation effect code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.