Custom Cursor Library with Animated Particle Effects – Cursorly.js
It works in all modern browsers that support the Canvas API. We’ve tested it successfully in Chrome, Firefox, Safari, and Edge.
The library uses requestAnimationFrame for smooth particle animations and handles mouse events efficiently enough for 60fps rendering on most hardware.
1. Download the package and load the main script Cursorly.js in your document.
<script src="/dist/cursorly.min.js"></script>
2. Initialize Cursorly.js with default options. This will create a custom cursor with a rainbow trail effect:
const cursor = Cursorly.init();
3. Customize the cursor icon (0-41):
const cursor = Cursorly.init({
cursor: 0, // Index of the cursor icon
}); 4. Customize the cursor effect. All available effect names:
const cursor = Cursorly.init({
cursor: 20,
effect: {
name: "trail",
color: "rainbow",
density: 10, // Optional: particles per mouse move
size: [3, 12], // Optional: min and max particle size
decay: 0.92, // Optional: particle shrink rate
type: "default", // Optional: define particle rendering type.
}
}); 5 You can also use a custom emoji. Just set the effect name to "emoji" and provide the character in the shape property.
const cursor = Cursorly.init({
cursor: 10,
effect: {
name: "emoji",
shape:"YOUR EMOJI HERE"
}
}); 6. Switch between cursor icons dynamically:
cursor.setIcon(1); // Changes to cursor at index 1 cursor.setIcon(5); // Changes to cursor at index 5
7. You can also define your own cursor effect that behave exactly like built-ins.
const starlightBurst = {
name: "starlightBurst",
color: ["#ffcc00", "#ffffff", "#ff99ff"],
density: 8,
size: [3, 9],
decay: 0.9,
type: "default"
};
cursor.setEffect(starlightBurst); 8. More API methods.
Q: How does Cursorly.js impact page performance?
A: It works by drawing particles on a fullscreen canvas element that sits behind your page content. The library is optimized to be lightweight, but a very high particle density on a complex, animation-heavy page could potentially affect performance.
Q: Why aren’t my custom emoji effects working?
A: Make sure you’re setting type: “emoji” and including the shape property with an actual emoji character. The name property can be anything for custom effects, but the type tells Cursorly how to render particles. Also verify your color property is set to “white” or a tint color, not an array.
Q: Does Cursorly work on mobile or touch devices?
A: The library tracks mouse events, so it doesn’t activate on touch-only devices where there’s no cursor. This is actually preferable for mobile UX since custom cursors can interfere with touch interactions. We recommend initializing Cursorly only on devices with pointer capability using matchMedia.
Q: How do I change cursor icons based on what element the user is hovering?
A: The library doesn’t automatically detect hover targets, but you can implement this with event listeners. Add mouseenter handlers to specific elements and call setIcon() when triggered. Remember to store the original icon index if you want to revert when the mouse leaves.
The post Custom Cursor Library with Animated Particle Effects – Cursorly.js appeared first on CSS Script.
Prime Video has published a The Boys Season 5, Episode 7 teaser trailer, revealing that…
A new video has revealed a ton of exciting new information on the original, scrapped…
Universal Pictures is inviting audiences to embark on a “digital odyssey” for director Christopher Nolan’s…
The Dungeon Crawler Carl series has been experiencing a whirlwind of a year so far…
Heads up: The massive 77" LG Evo C5 4K OLED Smart TV just dropped to…
After months of concerns regarding 007 First Light's performance, IO Interactive has confirmed the upcoming…
This website uses cookies.