123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- jQuery(document).ready(function($){
- var mainHeader = $('.v3listHead .m_top'),
- secondaryNavigation = $('.y_qylist'),
- //this applies only if secondary nav is below intro section
- belowNavHeroContent = $('.y_homelist_list'),
- headerHeight = mainHeader.height();
- //set scrolling variables
- var scrolling = false,
- previousTop = 0,
- currentTop = 0,
- scrollDelta = 10,
- scrollOffset = 150;
- $(window).on('scroll', function(){
- if( !scrolling ) {
- scrolling = true;
- (!window.requestAnimationFrame)
- ? setTimeout(autoHideHeader, 250)
- : requestAnimationFrame(autoHideHeader);
- }
- });
- $(window).on('resize', function(){
- headerHeight = mainHeader.height();
- });
- function autoHideHeader() {
- var currentTop = $(window).scrollTop();
- ( belowNavHeroContent.length > 0 )
- ? checkStickyNavigation(currentTop) // secondary navigation below intro
- : checkSimpleNavigation(currentTop);
- previousTop = currentTop;
- scrolling = false;
- }
- function checkSimpleNavigation(currentTop) {
- //there's no secondary nav or secondary nav is below primary nav
- if (previousTop - currentTop > scrollDelta) {
- //if scrolling up...
- mainHeader.removeClass('is-hidden');
- } else if( currentTop - previousTop > scrollDelta && currentTop > scrollOffset) {
- //if scrolling down...
- mainHeader.addClass('is-hidden');
- }
- }
- function checkStickyNavigation(currentTop) {
- //secondary nav below intro section - sticky secondary nav
- var secondaryNavOffsetTop = belowNavHeroContent.offset().top - secondaryNavigation.height() - mainHeader.height();
-
- if (previousTop >= currentTop ) {
- //if scrolling up...
- if( currentTop < secondaryNavOffsetTop ) {
- //secondary nav is not fixed
- mainHeader.removeClass('is-hidden');
- $('.v3listHead').removeClass('on'); //小明添加
- secondaryNavigation.removeClass('fixed slide-up');
- belowNavHeroContent.removeClass('secondary-nav-fixed');
- } else if( previousTop - currentTop > scrollDelta ) {
- //secondary nav is fixed
- mainHeader.removeClass('is-hidden');
- $('.v3listHead').removeClass('on'); //小明添加
- secondaryNavigation.removeClass('slide-up').addClass('fixed');
- belowNavHeroContent.addClass('secondary-nav-fixed');
- }
-
- } else {
- //if scrolling down...
- if( currentTop > secondaryNavOffsetTop + scrollOffset ) {
- //hide primary nav
- mainHeader.addClass('is-hidden');
- $('.v3listHead').addClass('on'); //小明添加
- secondaryNavigation.addClass('fixed slide-up');
- belowNavHeroContent.addClass('secondary-nav-fixed');
- } else if( currentTop > secondaryNavOffsetTop ) {
- //once the secondary nav is fixed, do not hide primary nav if you haven't scrolled more than scrollOffset
- mainHeader.removeClass('is-hidden');
- $('.v3listHead').removeClass('on'); //小明添加
- secondaryNavigation.addClass('fixed').removeClass('slide-up');
- belowNavHeroContent.addClass('secondary-nav-fixed');
- }
- }
- }
- });
|