www: clean ssr for lemondrop + respect prefers-reduced-motion (#174)
This commit is contained in:
@@ -16,13 +16,14 @@ function easeInCirc(x: number) {
|
|||||||
const waveTank = new WaveTank();
|
const waveTank = new WaveTank();
|
||||||
|
|
||||||
function LemonDrop() {
|
function LemonDrop() {
|
||||||
|
const SVG_WIDTH = 100;
|
||||||
const [counter, setCounter] = useState(0);
|
const [counter, setCounter] = useState(0);
|
||||||
const [dropy, setDropy] = useState(60);
|
const [dropy, setDropy] = useState(60);
|
||||||
const [width, setWidth] = useState(window.innerWidth);
|
const [width, setWidth] = useState(SVG_WIDTH);
|
||||||
const widthRef = useRef(width);
|
const widthRef = useRef(width);
|
||||||
const [springs, setSprings] = useState<Spring[]>([]);
|
const [springs, setSprings] = useState<Spring[]>(waveTank.springs);
|
||||||
const requestIdRef = useRef<number>();
|
const requestIdRef = useRef<number>();
|
||||||
const grid = width / waveTank.waveLength;
|
const grid = SVG_WIDTH / waveTank.waveLength;
|
||||||
const points = [
|
const points = [
|
||||||
[0, 100],
|
[0, 100],
|
||||||
[0, 0],
|
[0, 0],
|
||||||
@@ -80,6 +81,11 @@ function LemonDrop() {
|
|||||||
}, [width]);
|
}, [width]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||||
|
if (mediaQuery.matches) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
requestIdRef.current = requestAnimationFrame(update);
|
requestIdRef.current = requestAnimationFrame(update);
|
||||||
globalThis.addEventListener("resize", resize);
|
globalThis.addEventListener("resize", resize);
|
||||||
resize();
|
resize();
|
||||||
@@ -123,7 +129,13 @@ function LemonDrop() {
|
|||||||
fill="#fff"
|
fill="#fff"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<svg width={width} height="100" class={tw`-mt-5`}>
|
<svg
|
||||||
|
width="100%"
|
||||||
|
height="100px"
|
||||||
|
viewBox="0 0 100 100"
|
||||||
|
preserveAspectRatio="none"
|
||||||
|
class={tw`-mt-5`}
|
||||||
|
>
|
||||||
<polygon
|
<polygon
|
||||||
points={springsPath}
|
points={springsPath}
|
||||||
fill="white"
|
fill="white"
|
||||||
|
|||||||
Reference in New Issue
Block a user