瀏覽代碼

don't emulate scroll event

Gildas 7 年之前
父節點
當前提交
f2d641585d
共有 2 個文件被更改,包括 7 次插入5 次删除
  1. 2 1
      lib/single-file/lazy-loader-after.js
  2. 5 4
      lib/single-file/lazy-loader-before.js

+ 2 - 1
lib/single-file/lazy-loader-after.js

@@ -24,6 +24,7 @@
 
 	Element.prototype.getBoundingClientRect = window._singleFile_getBoundingClientRect;
 	delete window._singleFile_getBoundingClientRect;
-	dispatchEvent(new UIEvent("scroll"));
+	requestAnimationFrame(() => scrollBy(0, 1));
+	requestAnimationFrame(() => scrollBy(0, -1));
 
 })();

+ 5 - 4
lib/single-file/lazy-loader-before.js

@@ -18,19 +18,20 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global window, screen, dispatchEvent, Element, UIEvent */
+/* global window, screen, scrollBy, requestAnimationFrame, Element */
 
 (() => {
 
 	window._singleFile_getBoundingClientRect = Element.prototype.getBoundingClientRect;
 	Element.prototype.getBoundingClientRect = function () {
 		const boundingRect = window._singleFile_getBoundingClientRect.call(this);
-		const top = (boundingRect.top > 0 && boundingRect.top < screen.height) ? boundingRect.top : screen.height / 2;
-		const left = (boundingRect.left > 0 && boundingRect.left < screen.width) ? boundingRect.left : screen.width / 2;
+		const top = (boundingRect.top > 0 && boundingRect.top < screen.height) ? boundingRect.top : 0;
+		const left = (boundingRect.left > 0 && boundingRect.left < screen.width) ? boundingRect.left : 0;
 		const bottom = top + boundingRect.height;
 		const right = left + boundingRect.width;
 		return { x: boundingRect.x, y: boundingRect.y, top, bottom, left, right, width: boundingRect.width, height: boundingRect.height };
 	};
-	dispatchEvent(new UIEvent("scroll"));
+	requestAnimationFrame(() => scrollBy(0, 1));
+	requestAnimationFrame(() => scrollBy(0, -1));
 
 })();