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