Make WordPress Core

Changeset 26059


Ignore:
Timestamp:
11/09/2013 03:31:29 PM (13 years ago)
Author:
lancewillett
Message:

Twenty Fourteen: when header is more than 48px tall (like two lines of menu items), unfix the header so it doesn't overlap the page content. Props iamtakashi, fixes #25554.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/js/functions.js

    r25999 r26059  
    6060
    6161                /*
    62                  * Fixed navbar.
     62                 * Fixed header for large screen.
     63                 * If the header becomes more than 48px tall, unfix the header.
    6364                 *
    6465                 * The callback on the scroll event is only added if there is a header
    6566                 * image and we are not on mobile.
    6667                 */
    67                 if ( body.is( '.header-image' ) && _window.width() > 781 ) {
    68                         var toolbarOffset  = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0,
    69                             mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
     68                 if ( _window.width() > 781 ) {
     69                        var mastheadHeight = $( '#masthead' ).height();
    7070
    71                         _window.on( 'scroll.twentyfourteen', function() {
    72                                 if ( window.scrollY > mastheadOffset ) {
    73                                         body.addClass( 'masthead-fixed' );
    74                                 } else {
    75                                         body.removeClass( 'masthead-fixed' );
    76                                 }
    77                         } );
     71                        if ( mastheadHeight > 48 ) {
     72                                body.removeClass( 'masthead-fixed' );
     73                        }
     74
     75                        if ( body.is( '.header-image' ) ) {
     76                                var toolbarOffset  = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0,
     77                                    mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
     78
     79                                _window.on( 'scroll.twentyfourteen', function() {
     80                                        if ( ( window.scrollY > mastheadOffset ) && ( mastheadHeight < 49 ) ) {
     81                                                body.addClass( 'masthead-fixed' );
     82                                        } else {
     83                                                body.removeClass( 'masthead-fixed' );
     84                                        }
     85                                } );
     86                        }
    7887                }
    7988
Note: See TracChangeset for help on using the changeset viewer.