Skip to content

Commit db4a8ef

Browse files
authored
Merge pull request #71 from Darshan-SD/main
Cursor replaced with Magic Wand
2 parents 9d22b2c + 2855136 commit db4a8ef

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

assests/images/wand.png

1.51 KB
Loading

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</head>
1717

1818
<body>
19+
<img src="./assests/images/wand.png" class="custom-cursor" id="wandCursor" alt="Magic Wand">
1920
<div class="relative w-full h-screen overflow-hidden">
2021
<div class="light-sweep"></div>
2122
<audio id="submitSound" src="protego-105518.mp3" preload="auto"></audio>

script.js

+64-1
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,67 @@ document.addEventListener('DOMContentLoaded', function() {
409409
backgroundSound.play();
410410
backgroundSound.loop = true;
411411
});
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+
}

styles.css

+44
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
1+
* {
2+
cursor: none !important;
3+
}
4+
15
body {
26
font-family: "Arial", sans-serif;
37
background: radial-gradient(circle at center, #1b1f3b, #0a0c22, #000000);
48
margin: 0;
59
}
610

11+
.custom-cursor {
12+
position: absolute;
13+
pointer-events: none;
14+
width: 60px;
15+
/* Adjust the size of the wand */
16+
height: 60px;
17+
/* Adjust the size of the wand */
18+
transform: translate(-25%, -25%);
19+
transition: transform 0.1s ease-out;
20+
z-index: 10000;
21+
}
22+
23+
/* Sparkle particle style */
24+
.sparkle {
25+
position: absolute;
26+
width: 2.5px;
27+
height: 2.5px;
28+
background-color: rgba(255, 255, 255, 0.8);
29+
border-radius: 50%;
30+
pointer-events: none;
31+
animation: sparkle-animation 0.8s ease-out forwards;
32+
box-shadow: 0 0 10px 2px rgba(255, 157, 0, 0.5);
33+
transition: all 0.2s;
34+
z-index: 9999;
35+
}
36+
37+
/* Sparkle particle animation */
38+
@keyframes sparkle-animation {
39+
0% {
40+
transform: scale(1);
41+
opacity: 1;
42+
}
43+
100% {
44+
transform: scale(2);
45+
opacity: 0;
46+
}
47+
}
48+
49+
50+
751
.container {
852
max-width: 1918px;
953
padding: 20px;

0 commit comments

Comments
 (0)