From: Tim Düsterhus Date: Thu, 1 Sep 2016 01:36:27 +0000 (+0200) Subject: Avoid page jumping when scrolling is disabled X-Git-Tag: 3.0.0_Beta_1~370^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=65176a7fa9f2a5acf193e797b871733eab45472f;p=GitHub%2FWoltLab%2FWCF.git Avoid page jumping when scrolling is disabled --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Screen.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Screen.js index 50f3f7f361..ec9e726feb 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Screen.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Screen.js @@ -11,6 +11,7 @@ define(['Core', 'Dictionary'], function(Core, Dictionary) { var _mql = new Dictionary(); var _scrollDisableCounter = 0; + var _scrollOffsetFrom; var _mqMap = Dictionary.fromObject({ 'screen-xs': '(max-width: 544px)', /* smartphone */ @@ -95,6 +96,14 @@ define(['Core', 'Dictionary'], function(Core, Dictionary) { */ scrollDisable: function() { if (_scrollDisableCounter === 0) { + var h = document.body.scrollTop; + _scrollOffsetFrom = 'body'; + if (!h) { + h = document.documentElement.scrollTop; + _scrollOffsetFrom = 'documentElement'; + } + + elById('pageContainer').style.setProperty('transform', 'translateY(-' + h + 'px)'); document.documentElement.classList.add('disableScrolling'); } @@ -110,6 +119,11 @@ define(['Core', 'Dictionary'], function(Core, Dictionary) { if (_scrollDisableCounter === 0) { document.documentElement.classList.remove('disableScrolling'); + var h = elById('pageContainer').style.getPropertyValue('transform').match(/translateY\(-(\d+)px\)/); + elById('pageContainer').style.removeProperty('transform'); + if (h) { + document[_scrollOffsetFrom].scrollTop = ~~h[1]; + } } } },