mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-27 20:49:52 +01:00
feat: smooth curtains
This commit is contained in:
1 parent
58e0876aa0
commit
7a817cbe8c
2 files changed
+22
-11
No files matched your search
@@ -63,8 +63,7 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
transition: opacity var(--duration-brief);
|
|
||||||
|
|
||||||
&[data-side="left"] {
|
&[data-side="left"] {
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -75,9 +74,5 @@
|
|||||||
right: 0;
|
right: 0;
|
||||||
background: linear-gradient(90deg, transparent, var(--gray-1));
|
background: linear-gradient(90deg, transparent, var(--gray-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
&[data-visible="true"] {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useEffect, useRef, type ComponentProps } from "react";
|
import { useEffect, useRef, type ComponentProps } from "react";
|
||||||
|
import { clamp } from "three/src/math/MathUtils.js";
|
||||||
import { classNames } from "../../core/ui/classNames";
|
import { classNames } from "../../core/ui/classNames";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
@@ -36,13 +37,28 @@ export function Scroller({ children, className, ...props }: ScrollerProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function syncCurtains() {
|
function syncCurtains() {
|
||||||
const el = content.current;
|
const maxScroll =
|
||||||
|
content.current.scrollWidth - content.current.clientWidth;
|
||||||
|
if (maxScroll <= 0) {
|
||||||
|
curtainLeft.current.style.opacity = "0";
|
||||||
|
curtainRight.current.style.opacity = "0";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const showLeft = el.scrollLeft > 0;
|
const fadeDistance = Math.min(60, content.current.clientWidth * 0.15);
|
||||||
const showRight = el.scrollLeft + el.clientWidth < el.scrollWidth;
|
const leftOpacity = clamp(
|
||||||
|
content.current.scrollLeft / fadeDistance,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
const rightOpacity = clamp(
|
||||||
|
(maxScroll - content.current.scrollLeft) / fadeDistance,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
curtainLeft.current.dataset.visible = showLeft ? "true" : "false";
|
curtainLeft.current.style.opacity = `${leftOpacity}`;
|
||||||
curtainRight.current.dataset.visible = showRight ? "true" : "false";
|
curtainRight.current.style.opacity = `${rightOpacity}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastX = 0;
|
let lastX = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user