Parcourir la source

simulate scroll

Gildas il y a 7 ans
Parent
commit
20fc564df1
2 fichiers modifiés avec 17 ajouts et 2 suppressions
  1. 7 1
      lib/lazy/web-lazy-loader-after.js
  2. 10 1
      lib/lazy/web-lazy-loader-before.js

+ 7 - 1
lib/lazy/web-lazy-loader-after.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global window, requestAnimationFrame, scrollBy, Element */
+/* global window, requestAnimationFrame, scrollBy, Element, document */
 
 (() => {
 
@@ -29,4 +29,10 @@
 		requestAnimationFrame(() => scrollBy(0, -1));
 	}
 
+	if (window._singleFile_timeoutScroll) {
+		clearTimeout(window._singleFile_timeoutScroll);
+		window._singleFile_timeoutScroll = null;
+		delete document.documentElement.scrollTop;
+	}
+
 })();

+ 10 - 1
lib/lazy/web-lazy-loader-before.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global window, screen, scrollBy, requestAnimationFrame, Element */
+/* global window, screen, scrollBy, requestAnimationFrame, Element, document, dispatchEvent, UIEvent */
 
 (() => {
 
@@ -35,5 +35,14 @@
 	};
 	scrollBy(0, 1);
 	requestAnimationFrame(() => scrollBy(0, -1));
+	scroll(0);
+
+	function scroll(offsetY) {
+		document.documentElement.__defineGetter__("scrollTop", () => offsetY);
+		dispatchEvent(new UIEvent("scroll"));
+		if (offsetY < document.documentElement.offsetHeight) {
+			window._singleFile_timeoutScroll = setTimeout(() => scroll(offsetY + 100), 50);
+		}
+	}
 
 })();