File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -172,10 +172,9 @@ if (asset.alignment === "full-width") {
172172 />
173173 ) : (
174174 <video
175- class = " image"
175+ class = " image js-feature-video "
176176 src = { asset .path }
177177 aria-label = { asset .alt }
178- autoplay
179178 muted
180179 playsinline
181180 loop
Original file line number Diff line number Diff line change @@ -40,3 +40,26 @@ const features = await Promise.all(
4040 ))
4141 }
4242</section >
43+
44+ <script >
45+ // Play videos when they are in view, pause when they are not
46+ const videos = document.querySelectorAll(".js-feature-video");
47+
48+ const observer = new IntersectionObserver(
49+ (entries) => {
50+ entries.forEach((entry) => {
51+ const videoElement = entry.target as HTMLVideoElement;
52+ if (entry.isIntersecting) {
53+ videoElement.play();
54+ } else {
55+ videoElement.pause();
56+ }
57+ });
58+ },
59+ { threshold: 1 },
60+ );
61+
62+ videos.forEach((video) => {
63+ observer.observe(video);
64+ });
65+ </script >
You can’t perform that action at this time.
0 commit comments