Skip to content

Commit 4bb62da

Browse files
committed
Disable FutureSim hero video on mobile
1 parent e3fe148 commit 4bb62da

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

assets/blog.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,29 @@
259259
object-fit: cover;
260260
}
261261

262+
.futuresim-hero-poster {
263+
display: none;
264+
width: 100%;
265+
aspect-ratio: 16 / 9;
266+
height: auto;
267+
margin: 0;
268+
border: 0;
269+
border-radius: var(--radius-sm);
270+
box-shadow: none;
271+
background: #fff;
272+
object-fit: cover;
273+
}
274+
275+
@media (hover: none), (pointer: coarse), (max-width: 768px) {
276+
.futuresim-hero-video video {
277+
display: none;
278+
}
279+
280+
.futuresim-hero-poster {
281+
display: block;
282+
}
283+
}
284+
262285
/* Blog content styles */
263286
.blog-content {
264287
padding: 48px 0 72px;

assets/main.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,33 @@
4545

4646
document.querySelectorAll("[data-desktop-controls]").forEach((video) => {
4747
if (typeof window.matchMedia !== "function") return;
48-
const desktop = window.matchMedia("(min-width: 769px)");
48+
const desktop = window.matchMedia("(min-width: 769px) and (hover: hover) and (pointer: fine)");
49+
const sources = Array.from(video.querySelectorAll("source")).map((source) => ({
50+
el: source,
51+
src: source.getAttribute("src"),
52+
}));
53+
4954
const syncControls = () => {
50-
video.toggleAttribute("controls", desktop.matches);
55+
const isDesktop = desktop.matches;
56+
video.toggleAttribute("controls", isDesktop);
57+
video.toggleAttribute("autoplay", isDesktop);
58+
video.preload = isDesktop ? "auto" : "none";
59+
60+
sources.forEach(({ el, src }) => {
61+
if (!src) return;
62+
if (isDesktop && !el.getAttribute("src")) {
63+
el.setAttribute("src", src);
64+
} else if (!isDesktop && el.getAttribute("src")) {
65+
el.removeAttribute("src");
66+
}
67+
});
68+
69+
if (!isDesktop) {
70+
video.pause();
71+
video.load();
72+
} else if (!video.currentSrc) {
73+
video.load();
74+
}
5175
};
5276

5377
syncControls();
@@ -88,7 +112,7 @@
88112
root.style.setProperty("--active", String(index));
89113
if (tablist) tablist.style.setProperty("--active", String(index));
90114
if (panesRoot) panesRoot.style.setProperty("--active", String(index));
91-
if (focus) tabs[index]?.focus();
115+
if (focus && tabs[index]) tabs[index].focus();
92116
};
93117

94118
const stop = ({ permanent = false } = {}) => {

futuresim/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ nav: futuresim
4545

4646
<figure class="futuresim-hero-video">
4747
<video autoplay loop muted playsinline webkit-playsinline preload="auto" poster="{{ '/futuresim/figures/results/futuresim_combined_poster_v2.jpg' | relative_url }}" data-desktop-controls aria-label="FutureSim combined agent trajectory and benchmark animation">
48-
<source src="{{ '/futuresim/figures/results/futuresim_combined_v2.mp4' | relative_url }}" type="video/mp4">
48+
<source src="{{ '/futuresim/figures/results/futuresim_combined_v2.mp4' | relative_url }}" type="video/mp4" media="(min-width: 769px) and (hover: hover) and (pointer: fine)">
4949
</video>
50+
<img class="futuresim-hero-poster" src="{{ '/futuresim/figures/results/futuresim_combined_poster_v2.jpg' | relative_url }}" alt="FutureSim combined agent trajectory and benchmark preview.">
5051
</figure>
5152
</div>
5253
</section>

0 commit comments

Comments
 (0)