Fix menu shakiness when over-scrolling in Chrome and Safari on MacOS.
Merges [30844] to the 4.1 branch. See #30692. Built from https://develop.svn.wordpress.org/branches/4.1@30917 git-svn-id: http://core.svn.wordpress.org/branches/4.1@30907 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2c5c4f0567
commit
7736e255fc
|
@ -193,8 +193,11 @@ $(document).ready( function() {
|
||||||
lastScrollPosition = 0,
|
lastScrollPosition = 0,
|
||||||
pinnedMenuTop = false,
|
pinnedMenuTop = false,
|
||||||
pinnedMenuBottom = false,
|
pinnedMenuBottom = false,
|
||||||
|
isScrolling = false,
|
||||||
|
scrollTimer,
|
||||||
menuTop = 0,
|
menuTop = 0,
|
||||||
height = {
|
height = {
|
||||||
|
document: $document.height(),
|
||||||
window: $window.height(),
|
window: $window.height(),
|
||||||
wpwrap: $wpwrap.height(),
|
wpwrap: $wpwrap.height(),
|
||||||
adminbar: $adminbar.height(),
|
adminbar: $adminbar.height(),
|
||||||
|
@ -554,6 +557,35 @@ $(document).ready( function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( height.menu + height.adminbar > height.window ) {
|
if ( height.menu + height.adminbar > height.window ) {
|
||||||
|
// Check for overscrolling
|
||||||
|
if ( windowPos < 0 ) {
|
||||||
|
if ( ! pinnedMenuTop ) {
|
||||||
|
pinnedMenuTop = true;
|
||||||
|
pinnedMenuBottom = false;
|
||||||
|
|
||||||
|
$adminMenuWrap.css({
|
||||||
|
position: 'fixed',
|
||||||
|
top: '',
|
||||||
|
bottom: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if ( windowPos + height.window > height.document - 1 ) {
|
||||||
|
if ( ! pinnedMenuBottom ) {
|
||||||
|
pinnedMenuBottom = true;
|
||||||
|
pinnedMenuTop = false;
|
||||||
|
|
||||||
|
$adminMenuWrap.css({
|
||||||
|
position: 'fixed',
|
||||||
|
top: '',
|
||||||
|
bottom: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( windowPos > lastScrollPosition ) {
|
if ( windowPos > lastScrollPosition ) {
|
||||||
// Scrolling down
|
// Scrolling down
|
||||||
if ( pinnedMenuTop ) {
|
if ( pinnedMenuTop ) {
|
||||||
|
@ -626,6 +658,16 @@ $(document).ready( function() {
|
||||||
lastScrollPosition = windowPos;
|
lastScrollPosition = windowPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetHeights() {
|
||||||
|
height = {
|
||||||
|
document: $document.height(),
|
||||||
|
window: $window.height(),
|
||||||
|
wpwrap: $wpwrap.height(),
|
||||||
|
adminbar: $adminbar.height(),
|
||||||
|
menu: $adminMenuWrap.height()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function unpinMenu() {
|
function unpinMenu() {
|
||||||
if ( isIOS ) {
|
if ( isIOS ) {
|
||||||
return;
|
return;
|
||||||
|
@ -640,6 +682,8 @@ $(document).ready( function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPinMenu() {
|
function setPinMenu() {
|
||||||
|
resetHeights();
|
||||||
|
|
||||||
if ( $adminmenu.data('wp-responsive') ) {
|
if ( $adminmenu.data('wp-responsive') ) {
|
||||||
$body.removeClass( 'sticky-menu' );
|
$body.removeClass( 'sticky-menu' );
|
||||||
unpinMenu();
|
unpinMenu();
|
||||||
|
@ -652,8 +696,24 @@ $(document).ready( function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scrollStart() {
|
||||||
|
if ( isScrolling ) {
|
||||||
|
window.clearTimeout( scrollTimer );
|
||||||
|
|
||||||
|
scrollTimer = window.setTimeout( function() {
|
||||||
|
isScrolling = false;
|
||||||
|
}, 200 );
|
||||||
|
} else {
|
||||||
|
isScrolling = true;
|
||||||
|
$document.triggerHandler( 'wp-scroll-start' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! isIOS ) {
|
if ( ! isIOS ) {
|
||||||
$window.on( 'scroll.pin-menu', pinMenu );
|
$window.on( 'scroll.pin-menu', function() {
|
||||||
|
scrollStart();
|
||||||
|
pinMenu();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.wpResponsive = {
|
window.wpResponsive = {
|
||||||
|
@ -792,17 +852,7 @@ $(document).ready( function() {
|
||||||
window.wpResponsive.init();
|
window.wpResponsive.init();
|
||||||
setPinMenu();
|
setPinMenu();
|
||||||
|
|
||||||
$document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu', function() {
|
$document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
|
||||||
height.wpwrap = $wpwrap.height();
|
|
||||||
height.window = $window.height();
|
|
||||||
height.adminbar = $adminbar.height();
|
|
||||||
setPinMenu();
|
|
||||||
}).on( 'wp-collapse-menu.pin-menu', function() {
|
|
||||||
height.wpwrap = $wpwrap.height();
|
|
||||||
height.menu = $adminMenuWrap.height();
|
|
||||||
setPinMenu();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fire a custom jQuery event at the end of window resize
|
// Fire a custom jQuery event at the end of window resize
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue