« get me outta code hell

this commit is very large because i am doing work - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/lazy-loading.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2020-10-28 17:33:03 -0300
committer(quasar) nebula <towerofnix@gmail.com>2020-10-28 17:33:03 -0300
commit25798012d6a0ab3ba0c439f372bbedc5943ac47e (patch)
tree71dabc10f3283027d54c1d514ef1bf5e6d243800 /lazy-loading.js
parentf017dfe9c87bdf29430a26aa2b441d56e62c9195 (diff)
this commit is very large because i am doing work
and i would like to not lose progress in case i really screw those git
moves up bad

also it puts everything new into tracking which is kinda nice
Diffstat (limited to 'lazy-loading.js')
-rw-r--r--lazy-loading.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/lazy-loading.js b/lazy-loading.js
new file mode 100644
index 00000000..22f95eb0
--- /dev/null
+++ b/lazy-loading.js
@@ -0,0 +1,25 @@
+// Lazy loading! Roll your own. Woot.
+
+function loadImage(image) {
+    image.src = image.dataset.original;
+}
+
+function lazyLoad(elements) {
+    for (const item of elements) {
+        if (item.intersectionRatio > 0) {
+            observer.unobserve(item.target);
+            loadImage(item.target);
+        }
+    }
+}
+
+const observer = new IntersectionObserver(lazyLoad, {
+    rootMargin: '200px',
+    threshold: 1.0
+});
+
+for (const image of document.querySelectorAll('img.lazy')) {
+    observer.observe(image);
+}
+
+window.lazyLoadingExecuted = true;