Make WordPress Core

Ticket #52116: 52116.diff

File 52116.diff, 3.8 KB (added by nikunj8866, 18 months ago)

Attached patch to fix scrol jump

  • src/wp-content/themes/twentytwenty/assets/js/index.js

    diff --git a/src/wp-content/themes/twentytwenty/assets/js/index.js b/src/wp-content/themes/twentytwenty/assets/js/index.js
    index f5b142d239..f272a6f953 100644
    a b twentytwenty.coverModals = { 
    169169        // Hide and show modals before and after their animations have played out.
    170170        hideAndShowModals: function() {
    171171                var _doc = document,
    172                         _win = window,
    173                         modals = _doc.querySelectorAll( '.cover-modal' ),
    174                         htmlStyle = _doc.documentElement.style,
    175                         adminBar = _doc.querySelector( '#wpadminbar' );
    176 
    177                 function getAdminBarHeight( negativeValue ) {
    178                         var height,
    179                                 currentScroll = _win.pageYOffset;
    180 
    181                         if ( adminBar ) {
    182                                 height = currentScroll + adminBar.getBoundingClientRect().height;
    183 
    184                                 return negativeValue ? -height : height;
    185                         }
    186 
    187                         return currentScroll === 0 ? 0 : -currentScroll;
    188                 }
    189 
    190                 function htmlStyles() {
    191                         var overflow = _win.innerHeight > _doc.documentElement.getBoundingClientRect().height;
    192 
    193                         return {
    194                                 'overflow-y': overflow ? 'hidden' : 'scroll',
    195                                 position: 'fixed',
    196                                 width: '100%',
    197                                 top: getAdminBarHeight( true ) + 'px',
    198                                 left: 0
    199                         };
    200                 }
     172                        modals = _doc.querySelectorAll( '.cover-modal' );
    201173
    202174                // Show the modal.
    203175                modals.forEach( function( modal ) {
    204176                        modal.addEventListener( 'toggle-target-before-inactive', function( event ) {
    205                                 var styles = htmlStyles(),
    206                                         offsetY = _win.pageYOffset,
    207                                         paddingTop = ( Math.abs( getAdminBarHeight() ) - offsetY ) + 'px',
    208                                         mQuery = _win.matchMedia( '(max-width: 600px)' );
    209177
    210178                                if ( event.target !== modal ) {
    211179                                        return;
    212180                                }
    213181
    214                                 Object.keys( styles ).forEach( function( styleKey ) {
    215                                         htmlStyle.setProperty( styleKey, styles[ styleKey ] );
    216                                 } );
    217 
    218                                 _win.twentytwenty.scrolled = parseInt( styles.top, 10 );
    219 
    220                                 if ( adminBar ) {
    221                                         _doc.body.style.setProperty( 'padding-top', paddingTop );
    222 
    223                                         if ( mQuery.matches ) {
    224                                                 if ( offsetY >= getAdminBarHeight() ) {
    225                                                         modal.style.setProperty( 'top', 0 );
    226                                                 } else {
    227                                                         modal.style.setProperty( 'top', ( getAdminBarHeight() - offsetY ) + 'px' );
    228                                                 }
    229                                         }
    230                                 }
    231 
    232182                                modal.classList.add( 'show-modal' );
    233183                        } );
    234184
    235185                        // Hide the modal after a delay, so animations have time to play out.
    236186                        modal.addEventListener( 'toggle-target-after-inactive', function( event ) {
     187
    237188                                if ( event.target !== modal ) {
    238189                                        return;
    239190                                }
    240191
    241192                                setTimeout( function() {
    242                                         var clickedEl = twentytwenty.toggles.clickedEl;
    243193
    244194                                        modal.classList.remove( 'show-modal' );
    245195
    246                                         Object.keys( htmlStyles() ).forEach( function( styleKey ) {
    247                                                 htmlStyle.removeProperty( styleKey );
    248                                         } );
    249 
    250                                         if ( adminBar ) {
    251                                                 _doc.body.style.removeProperty( 'padding-top' );
    252                                                 modal.style.removeProperty( 'top' );
    253                                         }
    254 
    255                                         if ( clickedEl !== false ) {
    256                                                 clickedEl.focus();
    257                                                 clickedEl = false;
    258                                         }
    259 
    260                                         _win.scrollTo( 0, Math.abs( _win.twentytwenty.scrolled + getAdminBarHeight() ) );
    261 
    262                                         _win.twentytwenty.scrolled = 0;
    263196                                }, 500 );
    264197                        } );
    265198                } );
  • src/wp-content/themes/twentytwenty/style.css

    diff --git a/src/wp-content/themes/twentytwenty/style.css b/src/wp-content/themes/twentytwenty/style.css
    index 3ee6dbc431..71fa2c0e14 100644
    a b ul.social-icons li { 
    13331333
    13341334/* Cover Modals ------------------------------ */
    13351335
     1336body.showing-modal {
     1337        overflow: hidden;       
     1338}
     1339
    13361340.cover-modal {
    13371341        display: none;
    13381342        -ms-overflow-style: none;
    ul.social-icons li { 
    13461350.cover-modal.show-modal {
    13471351        display: block;
    13481352        cursor: pointer;
     1353        position: fixed;
     1354    height: 100%;
     1355    width: 100%;
     1356    overflow-x: hidden;
     1357    overflow-y: auto;
    13491358}
    13501359
    13511360.cover-modal.show-modal > * {