@@ -75,3 +75,55 @@ function notify(text) {
75
75
} , 500 ) ;
76
76
} , 3000 ) ;
77
77
}
78
+
79
+
80
+ let cursor = document . createElement ( "div" ) ;
81
+ cursor . setAttribute ( "id" , "cursor" ) ;
82
+ cursor . style = `
83
+ position: fixed;
84
+ border-radius: 100%;
85
+ box-shadow: 0 0 200px 80px #2079ff90;` ;
86
+ document . body . appendChild ( cursor ) ;
87
+
88
+ const mouse = { x : 0 , y : 0 } ;
89
+ const previousMouse = { x : 0 , y : 0 } ;
90
+ const circle = { x : 0 , y : 0 } ;
91
+ let currentScale = 0 ;
92
+
93
+ window . addEventListener ( "mousemove" , ( e ) => {
94
+ mouse . x = e . x ;
95
+ mouse . y = e . y ;
96
+ } ) ;
97
+
98
+ const speed = 0.17 ;
99
+
100
+ const tick = ( ) => {
101
+ // position
102
+ circle . x += ( mouse . x - circle . x ) * speed ;
103
+ circle . y += ( mouse . y - circle . y ) * speed ;
104
+ const position = `translate(${ circle . x } px, ${ circle . y } px)` ;
105
+
106
+ const deltaMouseX = mouse . x - previousMouse . x ;
107
+ const deltaMouseY = mouse . y - previousMouse . y ;
108
+
109
+ // scale
110
+ previousMouse . x = mouse . x ;
111
+ previousMouse . y = mouse . y ;
112
+ const mouseVelocity = Math . min (
113
+ Math . sqrt ( deltaMouseX ** 2 + deltaMouseY ** 2 ) * 10 ,
114
+ 150
115
+ ) ;
116
+ const scaleValue = ( mouseVelocity / 150 ) * 0.5 ;
117
+ currentScale += ( scaleValue - currentScale ) * speed ;
118
+ const scale = `scaleX(${ 1 + currentScale } ) scaleY(${ 1.5 - currentScale } )` ;
119
+
120
+ // rotate
121
+ const angle = ( Math . atan2 ( deltaMouseY , deltaMouseX ) * 180 ) / Math . PI ;
122
+ const rotate = `rotate(${ angle } deg)` ;
123
+
124
+ cursor . style . transform = position + rotate + scale ;
125
+
126
+ window . requestAnimationFrame ( tick ) ;
127
+ } ;
128
+
129
+ tick ( ) ;
0 commit comments