WordPress.org

Make WordPress Core

Ticket #42598: 42598.diff

File 42598.diff, 1.2 KB (added by jasonlcrane, 3 years ago)
  • src/wp-content/themes/twentyseventeen/assets/js/global.js

    diff --git a/src/wp-content/themes/twentyseventeen/assets/js/global.js b/src/wp-content/themes/twentyseventeen/assets/js/global.js
    index 6e2f429..4d70a8a 100644
    a b  
    182182                if ( $navigation.length ) {
    183183                        setNavProps();
    184184                        adjustScrollClass();
     185
     186                        // If something is in the URL hash when the page loads (and navigation is present)
     187                        // and if an element matching the hash is present on the page
     188                        if ( window.location.hash && $(window.location.hash).length ) {
     189                                // By the time this happens, the page has already scrolled to the element from the hash
     190                                // The scroll is wrapped in a timeout because we can't reliably determine
     191                                // when the browser changes scroll position
     192                                setTimeout(function() {
     193                                        // Set the window's scroll position to the current position, subtracting the nav height
     194                                        // and an extra 10px so the element doesn't touch the bottom of the nav
     195                                        $( window ).scrollTop( $(window).scrollTop() - navigationOuterHeight - 10 );
     196                                },100);
     197
     198                        }
    185199                }
    186200
    187201                // If 'Scroll Down' arrow in present on page, calculate scroll offset and bind an event handler to the click event.