-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from AswaniBolisetti/cursor-animation
added cursor animation
- Loading branch information
Showing
4 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export function fairyDustCursor() { | ||
const possibleColors = ["#D61C59", "#E7D84B", "#1B8798"]; | ||
|
||
let width = window.innerWidth; | ||
let height = window.innerHeight; | ||
|
||
const cursor = { x: width / 2, y: width / 2 }; | ||
const particles = []; | ||
|
||
// Helper function to create particle elements | ||
function createParticle(x, y) { | ||
const particle = document.createElement("div"); | ||
particle.classList.add("fairy-dust-particle"); | ||
particle.style.backgroundColor = | ||
possibleColors[Math.floor(Math.random() * possibleColors.length)]; | ||
particle.style.left = `${x}px`; | ||
particle.style.top = `${y + window.scrollY}px`; // Adjust the Y position based on scroll | ||
document.body.appendChild(particle); | ||
|
||
particles.push(particle); | ||
// Remove particle after animation | ||
setTimeout(() => { | ||
particle.remove(); | ||
}, 1000); | ||
} | ||
|
||
// Event listener for mouse movement | ||
document.addEventListener("mousemove", (e) => { | ||
cursor.x = e.clientX; | ||
cursor.y = e.clientY; | ||
createParticle(cursor.x, cursor.y); | ||
}); | ||
|
||
// Update width and height on window resize | ||
window.addEventListener("resize", () => { | ||
width = window.innerWidth; | ||
height = window.innerHeight; | ||
}); | ||
} |