Fixed static scroll offset calculation
authorAlexander Ebert <ebert@woltlab.com>
Sun, 18 Jun 2017 09:58:53 +0000 (11:58 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 18 Jun 2017 09:58:53 +0000 (11:58 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Scroll.js

index ace1b9f6a7f3af9b899564d69fd032ee03cff239..836ff82479cfd1b7bf60f8fabba873bc49ab29df 100644 (file)
@@ -11,6 +11,7 @@ define(['Dom/Util'], function(DomUtil) {
        
        var _callback = null;
        var _callbackScroll = null;
+       var _offset = null;
        var _timeoutScroll = null;
        
        /**
@@ -48,13 +49,28 @@ define(['Dom/Util'], function(DomUtil) {
                        }
                        
                        var y = DomUtil.offset(element).top;
-                       
-                       if (y <= 50) {
-                               y = 0;
+                       if (_offset === null) {
+                               _offset = 50;
+                               var pageHeader = elById('pageHeaderPanel');
+                               if (pageHeader !== null) {
+                                       var position = window.getComputedStyle(pageHeader).position;
+                                       if (position === 'fixed' || position === 'static') {
+                                               _offset = pageHeader.offsetHeight;
+                                       }
+                                       else {
+                                               _offset = 0;
+                                       }
+                               }
                        }
-                       else {
-                               // add an offset of 50 pixel to account for a sticky header
-                               y -= 50;
+                       
+                       if (_offset > 0) {
+                               if (y <= _offset) {
+                                       y = 0;
+                               }
+                               else {
+                                       // add an offset to account for a sticky header
+                                       y -= _offset;
+                               }
                        }
                        
                        var offset = window.pageYOffset;