Making WordPress.org

Changeset 11568


Ignore:
Timestamp:
02/17/2022 03:09:42 AM (2 years ago)
Author:
dd32
Message:

Support: Also Viewing: Account for the sticky global header.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js

    r10821 r11568  
    1010        page = options.currentPage || '',
    1111        banner = false,
     12        $adminbar = false,
     13        $header = false,
    1214        bannerOffset = 200,
    1315        isTyping = false,
     
    2123
    2224    jQuery( document ).ready( function() {
     25        $adminbar = jQuery('#wpadminbar');
     26        $header = jQuery('header.global-header');
     27
    2328        maybeDisplay();
    2429
     
    6974            );
    7075            banner.show();
    71             bannerOffset = banner.offset().top - jQuery('#wpadminbar').height();
     76
     77            // If we scroll past this number, we need to stick it to the viewport.
     78            // NOTE: There's a bug here - in short screen & mobile viewports it'll switch to fixed too early. meh.
     79            bannerOffset = $header.height() - $adminbar.height();
    7280        }
    7381    }
     
    7987        }
    8088
    81         var $main = jQuery('#main');
     89        var offset = 'var(--wp-admin--admin-bar--height, 0px)';
     90        if ( 'fixed' === $header.css('position') ) {
     91            offset = 'var(--wp-global-header-offset, 0px)';
     92        }
     93
    8294        if ( jQuery(window).scrollTop() > bannerOffset ) {
    8395            banner.css( 'position', 'fixed' );
    84             $main.css( 'padding-top', banner.height() );
     96            banner.css( 'top', offset );
    8597        } else {
    8698            banner.css( 'position', 'initial' );
    87             $main.css( 'padding-top', 0 );
     99            banner.css( 'top', '' );
    88100        }
    89101    } );
Note: See TracChangeset for help on using the changeset viewer.