@@ -423,4 +423,66 @@ window.addEventListener('scroll', function() {
423
423
{
424
424
toTop . classList . remove ( "active" )
425
425
}
426
- } ) ;
426
+ } ) ;
427
+
428
+ // Get the wand cursor
429
+ const wandCursor = document . getElementById ( 'wandCursor' ) ;
430
+ let lastMouseX = 0 ;
431
+ let lastMouseY = 0 ;
432
+
433
+ function wandPositionAnimation ( x , y ) {
434
+ createSparkle ( x , y ) ;
435
+ wandCursor . style . left = `${ x } px` ;
436
+ wandCursor . style . top = `${ y } px` ;
437
+ }
438
+
439
+ document . addEventListener ( 'mousemove' , function ( e ) {
440
+ lastMouseX = e . clientX ;
441
+ lastMouseY = e . clientY ;
442
+ wandPositionAnimation ( e . pageX , e . pageY )
443
+ } ) ;
444
+
445
+ document . addEventListener ( 'scroll' , function ( e ) {
446
+ const scrollX = window . scrollX ;
447
+ const scrollY = window . scrollY ;
448
+ const absoluteX = lastMouseX + scrollX ;
449
+ const absoluteY = lastMouseY + scrollY ;
450
+ wandPositionAnimation ( absoluteX , absoluteY )
451
+ } ) ;
452
+
453
+ function addRotation ( ) {
454
+ wandCursor . style . transform = 'rotate(45deg)' ;
455
+ wandCursor . style . transformOrigin = '50% 0%' ;
456
+ }
457
+
458
+ function removeRotation ( ) {
459
+ wandCursor . style . transform = 'translate(-25%, -25%)' ;
460
+ }
461
+
462
+ // Elements to hover over (button, label, etc.)
463
+ const hoverElements = [ 'button' , '.question label' , '#generateSpellBtn' ] ;
464
+
465
+ // Add event listeners to the elements
466
+ hoverElements . forEach ( hoverElement => {
467
+ var elements = document . querySelectorAll ( hoverElement ) ;
468
+ elements . forEach ( element => {
469
+ element . addEventListener ( 'mouseenter' , addRotation ) ;
470
+ element . addEventListener ( 'mouseleave' , removeRotation ) ;
471
+ } )
472
+ } ) ;
473
+
474
+ // Function to create sparkles at the given position
475
+ function createSparkle ( x , y ) {
476
+ const sparkle = document . createElement ( 'div' ) ;
477
+ sparkle . className = 'sparkle' ;
478
+ document . body . appendChild ( sparkle ) ;
479
+
480
+ const offsetX = ( Math . random ( ) - 0.5 ) * 40 ;
481
+ const offsetY = ( Math . random ( ) - 0.5 ) * 40 ;
482
+ sparkle . style . left = `${ x + offsetX } px` ;
483
+ sparkle . style . top = `${ y + offsetY } px` ;
484
+
485
+ setTimeout ( ( ) => {
486
+ sparkle . remove ( ) ;
487
+ } , 500 ) ;
488
+ }
0 commit comments