@@ -117,163 +117,3 @@ document.addEventListener('DOMContentLoaded', () => {
117117 }
118118} ) ;
119119
120- /**
121- * Pencil Cursor Animation
122- * Adds an interactive pencil cursor effect with trailing particles
123- * Responsive for different screen sizes and disabled on touch devices
124- */
125- ( function ( ) {
126- // Check if user prefers reduced motion
127- const prefersReducedMotion = window . matchMedia ( '(prefers-reduced-motion: reduce)' ) . matches ;
128- if ( prefersReducedMotion ) return ;
129-
130- // Check if device supports hover (has mouse/trackpad, not just touch)
131- const touchOnly = window . matchMedia ( '(hover: none) and (pointer: coarse)' ) . matches ;
132- if ( touchOnly ) return ; // Disable on touch-only devices
133-
134- let lastX = 0 ;
135- let lastY = 0 ;
136- let lastTrailTime = 0 ;
137-
138- // Responsive trail interval based on screen size
139- let trailInterval = 15 ; // milliseconds between trail particles (default for desktop)
140- if ( window . innerWidth <= 768 ) {
141- trailInterval = 20 ; // Slightly less frequent on tablets
142- }
143- if ( window . innerWidth <= 480 ) {
144- trailInterval = 25 ; // Even less frequent on mobile for performance
145- }
146-
147- // Determine particle size based on screen size
148- let particleSize = 6 ; // for 12px particles (12/2 = 6)
149- if ( window . innerWidth <= 768 ) {
150- particleSize = 5 ; // for 10px particles
151- }
152- if ( window . innerWidth <= 480 ) {
153- particleSize = 4 ; // for 8px particles
154- }
155-
156- // Determine mark size based on screen size
157- let markSize = 2.5 ; // for 5px marks (5/2 = 2.5)
158- if ( window . innerWidth <= 768 ) {
159- markSize = 2 ; // for 4px marks
160- }
161- if ( window . innerWidth <= 480 ) {
162- markSize = 1.5 ; // for 3px marks
163- }
164-
165- /**
166- * Create a trail particle at the cursor position
167- */
168- function createTrailParticle ( x , y ) {
169- const trail = document . createElement ( 'div' ) ;
170- trail . className = 'pencil-trail' ;
171- trail . style . left = ( x - particleSize ) + 'px' ; // center the particle
172- trail . style . top = ( y - particleSize ) + 'px' ;
173-
174- // Random slight offset for organic feel (responsive offset)
175- const maxOffset = window . innerWidth <= 480 ? 4 : 8 ;
176- const offsetX = ( Math . random ( ) - 0.5 ) * maxOffset ;
177- const offsetY = ( Math . random ( ) - 0.5 ) * maxOffset ;
178- trail . style . transform = `translate(${ offsetX } px, ${ offsetY } px)` ;
179-
180- document . body . appendChild ( trail ) ;
181-
182- // Remove particle after animation completes
183- setTimeout ( ( ) => trail . remove ( ) , 1000 ) ;
184- }
185-
186- /**
187- * Create a draw mark for occasional marks along the trail
188- */
189- function createDrawMark ( x , y ) {
190- const mark = document . createElement ( 'div' ) ;
191- mark . className = 'pencil-draw-mark' ;
192- mark . style . left = ( x - markSize ) + 'px' ; // center the mark
193- mark . style . top = ( y - markSize ) + 'px' ;
194-
195- // Random slight offset (responsive)
196- const maxOffset = window . innerWidth <= 480 ? 2 : 4 ;
197- const offsetX = ( Math . random ( ) - 0.5 ) * maxOffset ;
198- const offsetY = ( Math . random ( ) - 0.5 ) * maxOffset ;
199- mark . style . transform = `translate(${ offsetX } px, ${ offsetY } px)` ;
200-
201- document . body . appendChild ( mark ) ;
202-
203- // Remove mark after animation completes
204- setTimeout ( ( ) => mark . remove ( ) , 1200 ) ;
205- }
206-
207- /**
208- * Calculate distance between two points
209- */
210- function getDistance ( x1 , y1 , x2 , y2 ) {
211- return Math . sqrt ( Math . pow ( x2 - x1 , 2 ) + Math . pow ( y2 - y1 , 2 ) ) ;
212- }
213-
214- /**
215- * Handle mouse move for pencil trail effect
216- */
217- function handleMouseMove ( e ) {
218- const x = e . clientX ;
219- const y = e . clientY ;
220-
221- // Calculate distance moved
222- const distance = getDistance ( lastX , lastY , x , y ) ;
223-
224- // Create trail particles at intervals
225- const now = Date . now ( ) ;
226- if ( now - lastTrailTime > trailInterval ) {
227- createTrailParticle ( x , y ) ;
228- lastTrailTime = now ;
229-
230- // Occasionally create a draw mark for pencil marks effect
231- if ( Math . random ( ) > 0.5 ) {
232- createDrawMark ( x , y ) ;
233- }
234- }
235-
236- lastX = x ;
237- lastY = y ;
238- }
239-
240- /**
241- * Handle mouse leave to clean up
242- */
243- function handleMouseLeave ( ) {
244- lastX = 0 ;
245- lastY = 0 ;
246- }
247-
248- // Attach event listeners
249- document . addEventListener ( 'mousemove' , handleMouseMove , { passive : true } ) ;
250- document . addEventListener ( 'mouseleave' , handleMouseLeave ) ;
251-
252- // Handle window resize to update responsive values
253- let resizeTimeout ;
254- window . addEventListener ( 'resize' , ( ) => {
255- clearTimeout ( resizeTimeout ) ;
256- resizeTimeout = setTimeout ( ( ) => {
257- // Update trail interval on resize
258- if ( window . innerWidth <= 480 ) {
259- trailInterval = 25 ;
260- particleSize = 4 ;
261- markSize = 1.5 ;
262- } else if ( window . innerWidth <= 768 ) {
263- trailInterval = 20 ;
264- particleSize = 5 ;
265- markSize = 2 ;
266- } else {
267- trailInterval = 15 ;
268- particleSize = 6 ;
269- markSize = 2.5 ;
270- }
271- } , 250 ) ; // Debounce resize handler
272- } , { passive : true } ) ;
273-
274- // Cleanup on page unload
275- window . addEventListener ( 'beforeunload' , ( ) => {
276- document . removeEventListener ( 'mousemove' , handleMouseMove ) ;
277- document . removeEventListener ( 'mouseleave' , handleMouseLeave ) ;
278- } ) ;
279- } ) ( ) ;
0 commit comments