Autoplay and loop linked dataset trials
Browse files- assets/dataset_link.js +8 -7
assets/dataset_link.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
|
| 4 |
const CURSOR_COLOR = "#D55E00";
|
| 5 |
const PLAYBACK_DURATION_MS = 4200;
|
| 6 |
-
const autoplaySeen = new Set();
|
| 7 |
let activeState = null;
|
| 8 |
let scheduleGeneration = 0;
|
| 9 |
|
|
@@ -51,7 +50,7 @@
|
|
| 51 |
makeElement(
|
| 52 |
"span",
|
| 53 |
"dataset-link-hint",
|
| 54 |
-
"Hover the raster
|
| 55 |
)
|
| 56 |
);
|
| 57 |
|
|
@@ -174,7 +173,11 @@
|
|
| 174 |
const nextIndex = Math.min(finalIndex, startIndex + elapsedSteps);
|
| 175 |
if (nextIndex !== state.index) renderIndex(state, nextIndex);
|
| 176 |
if (nextIndex >= finalIndex) {
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
return;
|
| 179 |
}
|
| 180 |
state.animationFrame = requestAnimationFrame(advance);
|
|
@@ -245,12 +248,10 @@
|
|
| 245 |
|
| 246 |
function maybeAutoplay(state) {
|
| 247 |
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
| 248 |
-
|
| 249 |
-
if (reducedMotion || mobile || autoplaySeen.has(state.payload.dataset)) return;
|
| 250 |
state.intersectionObserver = new IntersectionObserver((entries) => {
|
| 251 |
const visible = entries.some((entry) => entry.isIntersecting && entry.intersectionRatio >= 0.25);
|
| 252 |
if (!visible || activeState !== state) return;
|
| 253 |
-
autoplaySeen.add(state.payload.dataset);
|
| 254 |
state.intersectionObserver.disconnect();
|
| 255 |
state.intersectionObserver = null;
|
| 256 |
state.autoplayTimer = window.setTimeout(() => {
|
|
@@ -258,7 +259,7 @@
|
|
| 258 |
renderIndex(state, 0);
|
| 259 |
play(state);
|
| 260 |
}
|
| 261 |
-
},
|
| 262 |
}, { threshold: [0.25] });
|
| 263 |
state.intersectionObserver.observe(state.controls);
|
| 264 |
}
|
|
|
|
| 3 |
|
| 4 |
const CURSOR_COLOR = "#D55E00";
|
| 5 |
const PLAYBACK_DURATION_MS = 4200;
|
|
|
|
| 6 |
let activeState = null;
|
| 7 |
let scheduleGeneration = 0;
|
| 8 |
|
|
|
|
| 50 |
makeElement(
|
| 51 |
"span",
|
| 52 |
"dataset-link-hint",
|
| 53 |
+
"Hover the raster or scrub the timeline to inspect a moment."
|
| 54 |
)
|
| 55 |
);
|
| 56 |
|
|
|
|
| 173 |
const nextIndex = Math.min(finalIndex, startIndex + elapsedSteps);
|
| 174 |
if (nextIndex !== state.index) renderIndex(state, nextIndex);
|
| 175 |
if (nextIndex >= finalIndex) {
|
| 176 |
+
state.animationFrame = requestAnimationFrame(() => {
|
| 177 |
+
if (!state.playing || activeState !== state) return;
|
| 178 |
+
renderIndex(state, 0);
|
| 179 |
+
play(state);
|
| 180 |
+
});
|
| 181 |
return;
|
| 182 |
}
|
| 183 |
state.animationFrame = requestAnimationFrame(advance);
|
|
|
|
| 248 |
|
| 249 |
function maybeAutoplay(state) {
|
| 250 |
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
| 251 |
+
if (reducedMotion) return;
|
|
|
|
| 252 |
state.intersectionObserver = new IntersectionObserver((entries) => {
|
| 253 |
const visible = entries.some((entry) => entry.isIntersecting && entry.intersectionRatio >= 0.25);
|
| 254 |
if (!visible || activeState !== state) return;
|
|
|
|
| 255 |
state.intersectionObserver.disconnect();
|
| 256 |
state.intersectionObserver = null;
|
| 257 |
state.autoplayTimer = window.setTimeout(() => {
|
|
|
|
| 259 |
renderIndex(state, 0);
|
| 260 |
play(state);
|
| 261 |
}
|
| 262 |
+
}, 150);
|
| 263 |
}, { threshold: [0.25] });
|
| 264 |
state.intersectionObserver.observe(state.controls);
|
| 265 |
}
|