@@ -28,6 +28,36 @@ export const Card: React.FC<CardProps> = ({
2828 const setProp = ( prop : string , value : string ) =>
2929 el . style . setProperty ( prop , value )
3030
31+ // Unified angle: mouse sets absolute; scroll applies incremental delta
32+ let ticking = false
33+ let lastScrollY = window . scrollY || window . pageYOffset || 0
34+ let angleDeg = ( ( ) => {
35+ const existing = el . style . getPropertyValue ( '--angle' )
36+ const parsed = parseFloat ( existing )
37+ return Number . isFinite ( parsed ) ? parsed : 45
38+ } ) ( )
39+
40+ const applyAngle = ( deg : number ) => {
41+ // Normalize within 0..360
42+ angleDeg = ( ( deg % 360 ) + 360 ) % 360
43+ setProp ( '--angle' , `${ angleDeg } deg` )
44+ }
45+
46+ const onScroll = ( ) => {
47+ const nowY = window . scrollY || window . pageYOffset || 0
48+ const deltaY = nowY - lastScrollY
49+ lastScrollY = nowY
50+ if ( deltaY === 0 ) return
51+ const deltaAngle = deltaY * 0.8
52+ if ( ticking ) return
53+ ticking = true
54+ requestAnimationFrame ( ( ) => {
55+ applyAngle ( angleDeg + deltaAngle )
56+ ticking = false
57+ } )
58+ }
59+ window . addEventListener ( 'scroll' , onScroll , { passive : true } )
60+
3161 const onMouseUpdate = ( e : MouseEvent ) => {
3262 const rect = el . getBoundingClientRect ( )
3363 const width = el . offsetWidth
@@ -43,7 +73,9 @@ export const Card: React.FC<CardProps> = ({
4373
4474 setProp ( '--dy' , `${ YAngle } deg` )
4575 setProp ( '--dx' , `${ XAngle } deg` )
46- setProp ( '--mouseAngle' , `${ Math . atan2 ( normY , normX ) } rad` )
76+ const angleRad = Math . atan2 ( normY , normX )
77+ const nextAngleDeg = ( angleRad * 180 ) / Math . PI
78+ applyAngle ( nextAngleDeg )
4779 setProp ( '--tx' , `${ normX } ` )
4880 setProp ( '--ty' , `${ normY } ` )
4981 const tiltMag = Math . min ( 1 , Math . sqrt ( normX * normX + normY * normY ) )
@@ -68,6 +100,7 @@ export const Card: React.FC<CardProps> = ({
68100 el . removeEventListener ( 'mousemove' , onMouseUpdate )
69101 el . removeEventListener ( 'mouseenter' , onMouseUpdate )
70102 el . removeEventListener ( 'mouseleave' , resetProps )
103+ window . removeEventListener ( 'scroll' , onScroll )
71104 }
72105 } , [ ] )
73106
0 commit comments