Skip to content

Commit a687c04

Browse files
Add scroll to top button
2 parents 1b789e9 + db4a8ef commit a687c04

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

assests/images/wand.png

1.51 KB
Loading

index.html

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

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

script.js

+63-1
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,66 @@ window.addEventListener('scroll', function() {
423423
{
424424
toTop.classList.remove("active")
425425
}
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+
}

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)