Skip to content

The swiss army knife of lossless video/audio editing

Website: on touch screens, draw the feature icons with a small IntersectionObserver script instead of a scroll-driven animation

Claude62429fa25793
diff --git a/website/README.md b/website/README.md
index 3c8ee2a5..edda06c1 100644
--- a/website/README.md
+++ b/website/README.md
@@ -27,7 +27,7 @@ App versions from before that link to `https://mifi.no/losslesscut/<name>` (same
## Homepage
-`src/pages/index.astro` (the `<head>`) and `src/components/Home.tsx` (the content), styled by `src/styles/home.css`, with its images in `src/assets/home/` (plus the store badges and the app icon from the repo). The content is a React component, rendered to static HTML at build time (no client-side JavaScript), so it can move to another React framework if needed. It doesn't use Starlight's components, since those bring Starlight's global CSS along (see `src/components/socialIcons.ts`).
+`src/pages/index.astro` (the `<head>`) and `src/components/Home.tsx` (the content), styled by `src/styles/home.css`, with its images in `src/assets/home/` (plus the store badges and the app icon from the repo). The content is a React component, rendered to static HTML at build time (no client-side JavaScript, except a small script in `index.astro` that animates the feature icons on touch screens), so it can move to another React framework if needed. It doesn't use Starlight's components, since those bring Starlight's global CSS along (see `src/components/socialIcons.ts`).
Official links (GitHub, stores, social media) are in `src/links.ts`.
diff --git a/website/src/components/Home.tsx b/website/src/components/Home.tsx
index 0d4505e0..9f48e7ae 100644
--- a/website/src/components/Home.tsx
+++ b/website/src/components/Home.tsx
@@ -1,4 +1,5 @@
-// The homepage content. Rendered to static HTML at build time (no client-side JavaScript).
+// The homepage content. Rendered to static HTML at build time (no client-side JavaScript, except a small script for the feature icon
+// animation in index.astro).
import type { CSSProperties, ReactNode } from 'react';
import type { IconNode } from 'lucide';
import { Combine, Film, Layers, ListOrdered, RefreshCw, ScanSearch, Scissors, SquarePen, Terminal } from 'lucide';
diff --git a/website/src/pages/index.astro b/website/src/pages/index.astro
index 0182c778..4a7c2e4f 100644
--- a/website/src/pages/index.astro
+++ b/website/src/pages/index.astro
@@ -34,5 +34,21 @@ const description = 'LosslessCut - Official downloads - free or paid version. Ed
</head>
<body>
<Home stars={stars} />
+ <script>
+ // On touch screens, draw each feature card's icon once when the card reaches the middle of the screen (.draw in home.css).
+ // (Scroll-driven CSS animations can't do this yet in all browsers, e.g. on iOS.) With a mouse, the icons draw on hover instead.
+ if (matchMedia('(hover: none) and (prefers-reduced-motion: no-preference)').matches && 'IntersectionObserver' in window) {
+ const observer = new IntersectionObserver((entries) => {
+ for (const { target, isIntersecting } of entries) {
+ if (isIntersecting) {
+ target.classList.add('draw');
+ observer.unobserve(target);
+ }
+ }
+ }, { rootMargin: '-35% 0px -35% 0px' }); // the middle 30% of the screen
+ document.querySelector('.feature-grid')?.classList.add('draw-on-scroll');
+ document.querySelectorAll('.feature-card').forEach((card) => observer.observe(card));
+ }
+ </script>
</body>
</html>
diff --git a/website/src/styles/home.css b/website/src/styles/home.css
index 3afe1866..ea6db199 100644
--- a/website/src/styles/home.css
+++ b/website/src/styles/home.css
@@ -291,8 +291,8 @@ go into extra columns to the side, which Safari didn't lay out again when opened
color: var(--accent);
background-color: color-mix(in srgb, var(--accent) 13%, white);
}
-/* The icon draws itself: on hover (desktop), and on phones when the card scrolls into view (where scroll-driven animations
-work; elsewhere the icons are just shown). Every line of the icon has pathLength 1 (Home.tsx), so a dash of 1 (with a gap of 2,
+/* The icon draws itself: on hover (desktop), and on touch screens once, when the card reaches the middle of the screen (.draw,
+set by the script in index.astro, which first sets .draw-on-scroll to hide the icons until then). Every line of the icon has pathLength 1 (Home.tsx), so a dash of 1 (with a gap of 2,
so that no dot of the next dash shows) draws each line from start to end in the same time. */
@keyframes feature-icon-draw {
from { stroke-dasharray: 1 2; stroke-dashoffset: 1; }
@@ -310,20 +310,12 @@ so that no dot of the next dash shows) draws each line from start to end in the
animation: feature-icon-draw 0.9s ease-out;
}
}
- @media (hover: none) {
- @supports (animation-timeline: view()) {
- .feature-card {
- view-timeline: --feature-card block;
- }
- /* separate properties: the minifier would otherwise merge animation-timeline into the animation shorthand, which browsers reject */
- .feature-icon svg * {
- animation-name: feature-icon-draw;
- animation-timing-function: linear;
- animation-fill-mode: both;
- animation-timeline: --feature-card;
- animation-range: entry 30% cover 45%;
- }
- }
+ .draw-on-scroll .feature-card:not(.draw) .feature-icon svg * {
+ stroke-dasharray: 1 2;
+ stroke-dashoffset: 1;
+ }
+ .feature-card.draw .feature-icon svg * {
+ animation: feature-icon-draw 0.9s ease-out;
}
}
/* phones: the icon next to the text, so the 9 cards take less space */