File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <script >
2+ import { onMount } from " svelte" ;
3+
4+ const { height = $bindable (0 ), width = $bindable (0 ), ... rest } = $props ();
5+
6+ let perHeight = $derived (Math .floor (height / 4 ));
7+ let perWidth = $derived (Math .floor (width / 4 ));
8+
9+ let halfHeight = $derived (perHeight * 2 );
10+
11+ /** @type {HTMLCanvasElement} */
12+ let canvas;
13+ /** @type {number} */
14+ let frame;
15+
16+ let offset = $state (0 );
17+
18+ onMount (() => {
19+ const context = canvas .getContext (" 2d" );
20+ context .strokeStyle = " white" ;
21+
22+ function animate () {
23+ context .clearRect (0 , 0 , width, height);
24+
25+ context .setLineDash ([width, width]);
26+ offset = offset - 5 ;
27+ context .lineDashOffset = offset;
28+
29+ context .beginPath ();
30+
31+ context .moveTo (0 , halfHeight);
32+ context .lineTo (perWidth, halfHeight);
33+ context .lineTo (perWidth * 2 , perHeight);
34+ context .lineTo (perWidth * 3 , halfHeight + perHeight);
35+
36+ context .lineTo (width, halfHeight);
37+ context .stroke ();
38+ frame = requestAnimationFrame (animate);
39+ }
40+
41+ animate ();
42+
43+ return () => cancelAnimationFrame (frame);
44+ });
45+ </script >
46+
47+ <canvas bind:this ={canvas } {height } {width } class =" fixed mx-auto" ></canvas >
Original file line number Diff line number Diff line change 11<script >
22 import " $styles/index.css" ;
33 import Navbar from " $components/Navbar.svelte" ;
4+ import Lines from " $components/Lines.svelte" ;
45
56 let { children } = $props ();
7+
8+ let innerHeight = $state (0 );
9+ let innerWidth = $state (0 );
610 </script >
711
812<svelte:head >
913 <link rel =" icon" href =" /favicon.png" />
1014</svelte:head >
1115
16+ <svelte:window bind:innerHeight bind:innerWidth />
17+
1218<Navbar />
1319
1420<main class =" grow bg-neutral-950 p-4 py-16 text-white" >
15- <div class =" mx-auto w-full max-w-3xl animate-up" >
21+ <Lines width ={innerWidth - 50 } height ={innerHeight } />
22+ <div class =" relative mx-auto w-full max-w-3xl animate-up" >
1623 {@render children ()}
1724 </div >
1825</main >
You can’t perform that action at this time.
0 commit comments