Skip to content

Commit 968a6b8

Browse files
committed
lil navbar fix and gif-like videos optimizations
1 parent 73d0a71 commit 968a6b8

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

app/components/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function Navbar() {
4141
const pathname = usePathname()
4242

4343
useEffect(() => {
44-
setIsDropdownEnabled(!isDropdownEnabled)
44+
setIsDropdownEnabled(false)
4545
}, [pathname])
4646

4747
return (
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use client'
2+
3+
import { useEffect, useRef, VideoHTMLAttributes } from "react"
4+
5+
export default function OptimizedLoopVideo({ src, className }: VideoHTMLAttributes<HTMLVideoElement>) {
6+
const videoRef = useRef<HTMLVideoElement>(null)
7+
8+
useEffect(() => {
9+
if (window["IntersectionObserver"] === undefined && window["IntersectionObserver"] === null)
10+
return;
11+
12+
if (!videoRef.current)
13+
return;
14+
15+
// lil debug stuff
16+
videoRef.current.onload = () => console.log("Video Loaded")
17+
videoRef.current.onplay = () => console.log("Video is playing");
18+
19+
const intersectionObserver = new IntersectionObserver((entries, observer) => {
20+
entries.forEach(video => {
21+
if (video.isIntersecting) {
22+
for (var source in video.target.children) {
23+
var videoSource = video.target.children[source] as HTMLVideoElement;
24+
if (typeof videoSource.tagName === "string" && videoSource.tagName === "SOURCE") {
25+
videoSource.src = videoSource.dataset.src as string;
26+
}
27+
}
28+
29+
console.log("Loading video");
30+
(video.target as HTMLVideoElement).load();
31+
video.target.classList.remove("lazy");
32+
intersectionObserver.unobserve(video.target);
33+
}
34+
});
35+
});
36+
37+
intersectionObserver.observe(videoRef.current)
38+
39+
return () => {
40+
intersectionObserver.disconnect()
41+
}
42+
}, [])
43+
44+
return <video
45+
ref={videoRef}
46+
autoPlay
47+
muted
48+
playsInline
49+
loop
50+
className={`lazy ${className}`}
51+
>
52+
<source data-src={src}/>
53+
</video>
54+
}

app/services/page.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Link from "next/link"
22
import Image from "next/image"
33
import { Paragraph, Chapter } from "../components/TextUtils"
44
import { StaticImport } from "next/dist/shared/lib/get-img-props"
5+
import OptimizedLoopVideo from "../components/OptimizedLoopVideo"
56

67
import volumeReconstructPng from "@/public/clients/baw/volume_reconstruct.png";
78
import n4ce_1 from "@/public/clients/apps_in_cadd/n4ce_1.jpg";
@@ -28,7 +29,7 @@ function PastProject({company, companyWebsite, images, videos, projects}: PastPr
2829
{projects.map((project, index) => <li key={index}>{project}</li>)}
2930
</ul>
3031
{(images || videos) &&
31-
<div className="grid grid-cols-1 md:grid-cols-2 p-4 justify-center">
32+
<div className="grid grid-cols-1 lg:grid-cols-2 p-4 justify-center">
3233
{images && images.map((image, index) =>
3334
<Image
3435
key={index}
@@ -38,13 +39,9 @@ function PastProject({company, companyWebsite, images, videos, projects}: PastPr
3839
/>
3940
)}
4041
{videos && videos.map((video, index) =>
41-
<video
42+
<OptimizedLoopVideo
4243
key={index}
4344
src={video}
44-
autoPlay
45-
muted
46-
playsInline
47-
loop
4845
className="aspect-video w-[500px]"
4946
/>
5047
)}

0 commit comments

Comments
 (0)