Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: make video fill screen

dev_wandryd8d049472891
diff --git a/app/(home)/components/sections/hero-scroll-video.tsx b/app/(home)/components/sections/hero-scroll-video.tsx
new file mode 100644
index 00000000..3ba52a25
--- /dev/null
+++ b/app/(home)/components/sections/hero-scroll-video.tsx
@@ -0,0 +1,180 @@
+"use client";
+
+import { Pause, Play } from "lucide-react";
+import {
+ motion,
+ useReducedMotion,
+ useScroll,
+ useTransform,
+} from "motion/react";
+import { type RefObject, useCallback, useEffect, useRef, useState } from "react";
+
+const REST_MAX_WIDTH = 1120;
+const REST_WIDTH_RATIO = 0.92;
+const CARD_ASPECT = 9 / 16;
+const REST_RADIUS = 24;
+const GROW_END = 0.28;
+const HOLD_END = 0.72;
+
+type Viewport = { w: number; h: number };
+
+export function HeroScrollVideo() {
+ const sectionRef = useRef<HTMLDivElement>(null);
+ const videoRef = useRef<HTMLVideoElement>(null);
+ const [playing, setPlaying] = useState(true);
+ const [viewport, setViewport] = useState<Viewport | null>(null);
+ const reduceMotion = useReducedMotion();
+
+ const togglePlay = useCallback(() => {
+ const v = videoRef.current;
+ if (!v) return;
+ if (v.paused) {
+ void v.play();
+ setPlaying(true);
+ } else {
+ v.pause();
+ setPlaying(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ const update = () =>
+ setViewport({ w: window.innerWidth, h: window.innerHeight });
+ update();
+ window.addEventListener("resize", update);
+ return () => window.removeEventListener("resize", update);
+ }, []);
+
+ if (reduceMotion || !viewport) {
+ return (
+ <div className="section">
+ <div className="relative mt-10 flex w-full justify-center sm:mt-12">
+ <div className="w-full max-w-[1120px]">
+ <VideoCard
+ videoRef={videoRef}
+ playing={playing}
+ onToggle={togglePlay}
+ className="aspect-video rounded-2xl sm:rounded-3xl"
+ />
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ return (
+ <ScrollStage
+ sectionRef={sectionRef}
+ videoRef={videoRef}
+ viewport={viewport}
+ playing={playing}
+ onToggle={togglePlay}
+ />
+ );
+}
+
+function ScrollStage({
+ sectionRef,
+ videoRef,
+ viewport,
+ playing,
+ onToggle,
+}: {
+ sectionRef: RefObject<HTMLDivElement | null>;
+ videoRef: RefObject<HTMLVideoElement | null>;
+ viewport: Viewport;
+ playing: boolean;
+ onToggle: () => void;
+}) {
+ const { scrollYProgress } = useScroll({
+ target: sectionRef,
+ offset: ["start start", "end end"],
+ });
+
+ const restWidth = Math.min(viewport.w * REST_WIDTH_RATIO, REST_MAX_WIDTH);
+ const restHeight = restWidth * CARD_ASPECT;
+ const keyframes = [0, GROW_END, HOLD_END, 1];
+
+ const width = useTransform(scrollYProgress, keyframes, [
+ restWidth,
+ viewport.w,
+ viewport.w,
+ restWidth,
+ ]);
+ const height = useTransform(scrollYProgress, keyframes, [
+ restHeight,
+ viewport.h,
+ viewport.h,
+ restHeight,
+ ]);
+ const borderRadius = useTransform(scrollYProgress, keyframes, [
+ REST_RADIUS,
+ 0,
+ 0,
+ REST_RADIUS,
+ ]);
+
+ return (
+ <section ref={sectionRef} data-hero-zoom className="relative h-[380vh]">
+ <div className="sticky top-0 flex h-screen w-full items-center justify-center overflow-hidden">
+ <motion.div
+ style={{ width, height, borderRadius }}
+ className="group surface-card relative overflow-hidden shadow-black/5 will-change-[width,height] dark:shadow-black/40"
+ >
+ <VideoCard
+ videoRef={videoRef}
+ playing={playing}
+ onToggle={onToggle}
+ className="h-full w-full"
+ />
+ </motion.div>
+ </div>
+ </section>
+ );
+}
+
+function VideoCard({
+ videoRef,
+ playing,
+ onToggle,
+ className,
+}: {
+ videoRef: RefObject<HTMLVideoElement | null>;
+ playing: boolean;
+ onToggle: () => void;
+ className?: string;
+}) {
+ return (
+ <div className={`group relative overflow-hidden ${className ?? ""}`}>
+ <video
+ ref={videoRef}
+ src="/introducing-remocn.mp4"
+ autoPlay
+ muted
+ loop
+ playsInline
+ preload="metadata"
+ poster="/introducing-remocn-poster.jpg"
+ className="block h-full w-full object-cover"
+ />
+ <button
+ type="button"
+ onClick={onToggle}
+ aria-label={playing ? "Pause preview" : "Play preview"}
+ className="absolute inset-0 flex items-center justify-center bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
+ >
+ <span
+ aria-hidden
+ data-show={!playing}
+ className="pointer-events-none flex size-14 items-center justify-center rounded-full bg-background/70 text-foreground opacity-0 backdrop-blur-md transition-opacity duration-200 group-hover:opacity-100 motion-reduce:transition-none data-[show=true]:opacity-100"
+ >
+ {playing ? (
+ <Pause className="size-5" />
+ ) : (
+ <Play className="size-5 translate-x-0.5" />
+ )}
+ </span>
+ </button>
+ </div>
+ );
+}
diff --git a/app/(home)/components/sections/hero.tsx b/app/(home)/components/sections/hero.tsx
index 78310890..ea7c7119 100644
--- a/app/(home)/components/sections/hero.tsx
+++ b/app/(home)/components/sections/hero.tsx
@@ -1,36 +1,18 @@
"use client";
-import { ArrowRight, Pause, Play } from "lucide-react";
-import { motion } from "motion/react";
+import { ArrowRight } from "lucide-react";
import Link from "next/link";
-import { useCallback, useRef, useState } from "react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
-import { SPRING_BOUNCE } from "@/config/site";
import { useTrackEvent } from "@/lib/analytics";
import { FadeUp } from "../fade-up";
import { HeroNeuroBg } from "../hero-shader-bg";
import { InstallAll } from "../install-all";
+import { HeroScrollVideo } from "./hero-scroll-video";
export function Hero() {
- const videoRef = useRef<HTMLVideoElement>(null);
- const [playing, setPlaying] = useState(true);
const trackEvent = useTrackEvent();
- const togglePlay = useCallback(() => {
- const v = videoRef.current;
- if (!v) return;
- if (v.paused) {
- void v.play();
- setPlaying(true);
- } else {
- v.pause();
- setPlaying(false);
- }
- }, []);
-
- const aspectRatio = "16 / 9";
-
return (
<section className="relative isolate pt-10 pb-16 sm:pt-16 sm:pb-24">
<div aria-hidden className="absolute inset-0 -z-10">
@@ -105,52 +87,7 @@ export function Hero() {
</div>
</div>
- <div className="section">
- <FadeUp delay={0.24} className="relative mt-10 w-full sm:mt-12">
- <motion.div
- className="relative"
- initial={{ y: 40, opacity: 0 }}
- whileInView={{ y: 0, opacity: 1 }}
- viewport={{ once: true, amount: 0.2 }}
- transition={{ ...SPRING_BOUNCE, delay: 0.05 }}
- >
- <div
- className="group surface-card relative w-full overflow-hidden rounded-2xl shadow-black/5 sm:rounded-3xl dark:shadow-black/40"
- style={{ aspectRatio }}
- >
- <video
- ref={videoRef}
- src="/introducing-remocn.mp4"
- autoPlay
- muted
- loop
- playsInline
- preload="metadata"
- poster="/introducing-remocn-poster.jpg"
- className="block h-full w-full object-cover"
- />
- <button
- type="button"
- onClick={togglePlay}
- aria-label={playing ? "Pause preview" : "Play preview"}
- className="absolute inset-0 flex items-center justify-center bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
- >
- <span
- aria-hidden
- data-show={!playing}
- className="pointer-events-none flex size-14 items-center justify-center rounded-full bg-background/70 text-foreground opacity-0 backdrop-blur-md transition-opacity duration-200 group-hover:opacity-100 motion-reduce:transition-none data-[show=true]:opacity-100"
- >
- {playing ? (
- <Pause className="size-5" />
- ) : (
- <Play className="size-5 translate-x-0.5" />
- )}
- </span>
- </button>
- </div>
- </motion.div>
- </FadeUp>
- </div>
+ <HeroScrollVideo />
</section>
);
}
diff --git a/app/(home)/components/sticky-header-shell.tsx b/app/(home)/components/sticky-header-shell.tsx
index 06443c3c..7b7247d2 100644
--- a/app/(home)/components/sticky-header-shell.tsx
+++ b/app/(home)/components/sticky-header-shell.tsx
@@ -1,24 +1,81 @@
"use client";
-import type { ReactNode } from "react";
+import { animate, motion, useMotionValue } from "motion/react";
+import { type ReactNode, useEffect, useRef } from "react";
import { useScroll } from "@/hooks/use-scroll";
import { cn } from "@/lib/utils";
+const HEADER_HEIGHT = 88;
+const REVEAL_SPRING = {
+ type: "spring",
+ stiffness: 480,
+ damping: 34,
+ mass: 0.9,
+} as const;
+
export function StickyHeaderShell({ children }: { children: ReactNode }) {
const scrolled = useScroll();
+ const headerRef = useRef<HTMLElement>(null);
+ const y = useMotionValue(0);
+ const prevPast = useRef<boolean | null>(null);
+ const animating = useRef(false);
+
+ useEffect(() => {
+ const evaluate = () => {
+ const height = headerRef.current?.offsetHeight ?? HEADER_HEIGHT;
+ const zoom = document.querySelector<HTMLElement>("[data-hero-zoom]");
+
+ if (!zoom) {
+ y.set(0);
+ prevPast.current = true;
+ return;
+ }
+
+ const past = zoom.getBoundingClientRect().bottom <= window.innerHeight;
+ const first = prevPast.current === null;
+
+ if (!first && past !== prevPast.current) {
+ animating.current = true;
+ animate(y, past ? 0 : -height, REVEAL_SPRING).then(() => {
+ animating.current = false;
+ });
+ } else if (past) {
+ if (first) y.set(0);
+ } else if (!animating.current) {
+ y.set(-Math.min(window.scrollY, height));
+ }
+
+ prevPast.current = past;
+ };
+
+ evaluate();
+ window.addEventListener("scroll", evaluate, { passive: true });
+ window.addEventListener("resize", evaluate);
+ return () => {
+ window.removeEventListener("scroll", evaluate);
+ window.removeEventListener("resize", evaluate);
+ };
+ }, [y]);
return (
- <header className="sticky inset-x-0 top-0 z-40 py-3">
- <div
- className={cn(
- "mx-auto flex w-full max-w-6xl items-center justify-between rounded-3xl border px-4 transition-all duration-300 sm:px-6",
- scrolled
- ? "h-14 border-border bg-background/80 shadow-lg shadow-black/5 backdrop-blur-xl dark:shadow-black/30"
- : "h-16 border-transparent bg-transparent",
- )}
+ <>
+ <motion.header
+ ref={headerRef}
+ style={{ y }}
+ className="fixed inset-x-0 top-0 z-40 py-3"
>
- {children}
- </div>
- </header>
+ <div
+ className={cn(
+ "mx-auto flex w-full max-w-6xl items-center justify-between rounded-3xl border px-4 transition-all duration-300 sm:px-6",
+ scrolled
+ ? "h-14 border-border bg-background/80 shadow-lg shadow-black/5 backdrop-blur-xl dark:shadow-black/30"
+ : "h-16 border-transparent bg-transparent",
+ )}
+ >
+ {children}
+ </div>
+ </motion.header>
+ <div aria-hidden className="h-[88px]" />
+ </>
);
}