mirror of
https://github.com/greflm13/StaticGalleryBuilder.git
synced 2026-04-17 11:30:08 +02:00
different prefetch
This commit is contained in:
@@ -353,6 +353,13 @@ input {
|
|||||||
left: calc(50% + 1em - 1px);
|
left: calc(50% + 1em - 1px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.imgprefetch {
|
||||||
|
position: absolute;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 1000px) {
|
@media screen and (max-width: 1000px) {
|
||||||
.column {
|
.column {
|
||||||
-ms-flex: 25%;
|
-ms-flex: 25%;
|
||||||
|
|||||||
@@ -47,22 +47,21 @@ class PhotoGallery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prefetch(imgIndex) {
|
prefetch(imgIndex) {
|
||||||
if (this.controllers[imgIndex]) {
|
const prefetchDiv = document.getElementById("img-prefetch");
|
||||||
this.cancel(imgIndex);
|
if (!prefetchDiv) return;
|
||||||
}
|
|
||||||
const controller = new AbortController();
|
const img = document.createElement("img");
|
||||||
const signal = controller.signal;
|
img.src = this.shown[imgIndex]?.src || "";
|
||||||
this.controllers[imgIndex] = controller;
|
prefetchDiv.appendChild(img);
|
||||||
const urlToFetch = this.shown[imgIndex]?.src;
|
|
||||||
if (urlToFetch) {
|
|
||||||
fetch(urlToFetch, { method: "GET", signal }).catch(() => {});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel(imgIndex) {
|
cancel(imgIndex) {
|
||||||
if (this.controllers[imgIndex]) {
|
const prefetchDiv = document.getElementById("img-prefetch");
|
||||||
this.controllers[imgIndex].abort();
|
if (!prefetchDiv) return;
|
||||||
delete this.controllers[imgIndex];
|
|
||||||
|
const img = prefetchDiv.querySelector(`img[src="${this.shown[imgIndex]?.src || ""}"]`);
|
||||||
|
if (img) {
|
||||||
|
prefetchDiv.removeChild(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +392,7 @@ class PhotoGallery {
|
|||||||
if (!isNaN(index)) this.openSwipe(index);
|
if (!isNaN(index)) this.openSwipe(index);
|
||||||
});
|
});
|
||||||
|
|
||||||
imagelist.addEventListener("mouseover", (event) => {
|
imagelist.addEventListener("mouseenter", (event) => {
|
||||||
const img = event.target.closest("img");
|
const img = event.target.closest("img");
|
||||||
if (!img || !img.dataset.index) return;
|
if (!img || !img.dataset.index) return;
|
||||||
const index = parseInt(img.dataset.index);
|
const index = parseInt(img.dataset.index);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
<script src="{{ root }}.static/functionality.min.js"></script>
|
<script src="{{ root }}.static/functionality.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<ol class="navbar">
|
<ol class="navbar">
|
||||||
<div class="navleft">
|
<div class="navleft">
|
||||||
@@ -197,6 +197,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="imgprefetch" id="img-prefetch"></div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
new PhotoGallery();
|
new PhotoGallery();
|
||||||
|
|||||||
Reference in New Issue
Block a user