From 65176a7fa9f2a5acf193e797b871733eab45472f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 1 Sep 2016 03:36:27 +0200 Subject: [PATCH] Avoid page jumping when scrolling is disabled --- .../files/js/WoltLabSuite/Core/Ui/Screen.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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]; + } } } }, -- 2.20.1