File tree 1 file changed +8
-7
lines changed
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,14 @@ import "./sensor.css";
4
4
export function Sensor ( ) {
5
5
const [ val , setVal ] = createSignal < number > ( 0 ) ;
6
6
createEffect ( ( ) => {
7
- ( function rand ( ) {
8
- setVal ( Math . floor ( Math . random ( ) * 100 ) ) ;
9
- setTimeout ( rand , Math . random ( ) * 200 + 50 ) ;
10
- } ) ( ) ;
11
- // window.addEventListener("mousemove", (e) => {
12
- // setVal(Math.max(0, Math.min(99, Math.abs(e.movementX) + Math.abs(e.movementY))));
13
- // });
7
+ function scrollPercent ( ) {
8
+ const scroll = document . documentElement . scrollTop ;
9
+ const height = document . documentElement . scrollHeight - document . documentElement . clientHeight ;
10
+ setVal ( 100 - Math . round ( ( scroll / height ) * 100 ) ) ;
11
+ }
12
+
13
+ window . addEventListener ( "scroll" , scrollPercent ) ;
14
+ return ( ) => window . removeEventListener ( "scroll" , scrollPercent ) ;
14
15
} ) ;
15
16
16
17
return < span id = "sensor" > { val ( ) . toString ( ) . padStart ( 2 , "0" ) } </ span > ;
You can’t perform that action at this time.
0 commit comments