Skip to content

Commit

Permalink
Batch updates into single dom update
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Jul 5, 2023
1 parent 8580a08 commit ff5baa7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
3 * Math.pow(t, 2) * (1 - t) * p2[1] +
Math.pow(t, 3) * p3[1];
return { x, y };
return [x, y];
}
let scrollY = 0;
Expand All @@ -94,8 +94,20 @@
$: circle_r = 1000 / innerWidth;
$: circles = Math.floor(innerWidth / 100);
$: circle_coords = new Array(circles).fill(0).map((_) => ({ x: 0, y: 0 }));
$: if (browser && $scroll >= 0 && $scroll <= 1)
requestAnimationFrame(animate);
function animate() {
circle_coords.forEach((c, i) => {
[c.x, c.y] = circle($scroll - i / circles);
});
circle_coords = circle_coords;
}
function circle(scroll: number) {
if (scroll < 0 || scroll > 1) return { x: 0, y: 0 };
if (scroll < 0 || scroll > 1) return [0, 0];
const i = lengths.findIndex((p) => p >= scroll);
Expand Down Expand Up @@ -165,8 +177,7 @@
/>

{#if $scroll <= 1}
{#each new Array(circles) as _, i}
{@const c = circle($scroll - i * (1.0 / circles))}
{#each circle_coords as c}
<circle
cx={c.x}
cy={c.y - circle_r}
Expand Down

0 comments on commit ff5baa7

Please sign in to comment.