Skip to content

The swiss army knife of lossless video/audio editing

Website: draw feature icons that are on screen when scrolling stops, so they don't stay blank after a jump

Claudecc9a7b2e65a5
diff --git a/website/src/components/Home.tsx b/website/src/components/Home.tsx
index 7dbeea2c..011d0e43 100644
--- a/website/src/components/Home.tsx
+++ b/website/src/components/Home.tsx
@@ -164,7 +164,7 @@ export default function Home({ stars }: { stars: number }) {
<div className="hero-media">
{demoSources.length > 0 ? (
- // controls: a looping video must be pausable (WCAG 2.2.2), and the page has no JavaScript for a custom button
+ // controls: a looping video must be pausable (WCAG 2.2.2), and there's no script for a custom button
<video autoPlay muted loop playsInline controls width={1000} height={624} poster={mainScreenshot} aria-label="LosslessCut cutting a video">
{demoSources.map(({ url, type }) => <source key={url} src={url} type={type} />)}
</video>
diff --git a/website/src/pages/index.astro b/website/src/pages/index.astro
index 07d8d542..3faac516 100644
--- a/website/src/pages/index.astro
+++ b/website/src/pages/index.astro
@@ -37,15 +37,31 @@ const description = 'LosslessCut - Official downloads - free or paid version. Ed
<!-- is:inline: plain JS, not compiled by Vite, which would look for a tsconfig and find the app's (see tsconfig.json) -->
<script is:inline>
// On touch screens, draw each feature card's icon when the card reaches the middle of the screen (.draw in home.css), again
- // after it has left the screen, and when it's tapped. (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.
+ // after it has left the screen, and when it's tapped. Cards that are on screen when scrolling stops without having passed the
+ // middle (after a jump to a link, or a fast scroll) are drawn then. (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 inMiddle = new IntersectionObserver((entries) => {
for (const { target, isIntersecting } of entries) if (isIntersecting) target.classList.add('draw');
}, { rootMargin: '-35% 0px -35% 0px' }); // the middle 30% of the screen
+ const visibleCards = new Set();
const onScreen = new IntersectionObserver((entries) => {
- for (const { target, isIntersecting } of entries) if (!isIntersecting) target.classList.remove('draw');
+ for (const { target, isIntersecting } of entries) {
+ if (isIntersecting) {
+ visibleCards.add(target);
+ } else {
+ visibleCards.delete(target);
+ target.classList.remove('draw');
+ }
+ }
});
+ let scrollStopTimer;
+ const drawVisibleWhenScrollStops = () => {
+ clearTimeout(scrollStopTimer);
+ scrollStopTimer = setTimeout(() => visibleCards.forEach((card) => card.classList.add('draw')), 300);
+ };
+ addEventListener('scroll', drawVisibleWhenScrollStops, { passive: true });
+ drawVisibleWhenScrollStops();
document.querySelector('.feature-grid')?.classList.add('draw-on-scroll');
document.querySelectorAll('.feature-card').forEach((card) => {
inMiddle.observe(card);