Customize cursor with optional effects. Show magic with your mouse / cursor!
Cursorly.js is a lightweight JavaScript library that replaces the default browser cursor with customizable icons and interactive particle effects like trail or sparkle. Itβs designed to be developer-friendly, flexible, and fun β perfect for creative websites, portfolios, or experimental UI design.
How to set a custom emoji effect:
// Initialize first if not done yet
const cursor = Cursorly.init();
// Set custom emoji effect
cursor.setEffect({name:"emoji", shape:"π»", size:[2,4]});
// Keep your emoji in shape and it's required, size, density,decay,color is optional.
Click on an emoji to set it as the cursor effect:
Include the library via CDN:
<script src="https://cdn.jsdelivr.net/gh/iamashruu/cursorly.js@v1.0.1/dist/cursorly.min.js"></script>
Initialize the cursor with default options:
const cursor = Cursorly.init({
cursor: 0, // Index of the cursor icon (default: 0)
effect: { name: "trail", color: "rainbow" } // Effect name and color are required
});
Hereβs a complete example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cursorly.js Example</title>
<script src="https://cdn.jsdelivr.net/gh/iamashruu/cursorly.js@v1.0.1/dist/cursorly.min.js"></script>
</head>
<body>
<script>
const cursor = Cursorly.init();
</script>
</body>
</html>
// Initialization with default icons and effect
const cursor = Cursorly.init();
// OR, Initialize with custom icon and effect:
const cursor = Cursorly.init({
cursor: 0, // Index of the cursor icon (default: 0)
effect: { name: "trail", color: "rainbow" } // Effect name and color are required
});
// OR, Initialize with custom icon and emoji effect
const cursor = Cursorly.init({
cursor: 0,
effect: { name: "emoji", shape:"π»"}
});
// Change cursor icon dynamically
cursor.setIcon(1);
// Change particle effect dynamically
cursor.setEffect({
name: "sparkle", // 'trail', 'sparkle', or 'emojiSnow',etc
color: "#ff4081", // Hex color or "rainbow"
density: 10, // Optional, number of particles per mouse move
size: [3, 12], // Optional, min and max particle size
decay: 0.92, // Optional, particle shrink rate
});
// Set custom emoji effect
cursor.setEffect({
name: "emoji", // 'trail', 'sparkle', or 'none'
shape: "π»", // emoji
density: 10, // Optional, number of particles per mouse move
size: [3, 12], // Optional, min and max particle size
decay: 0.92, // Optional, particle shrink rate
});
//Disable or enable effects dynamically::
cursor.disableEffect(); // Turn off particle effects
cursor.enableEffect(); // Turn on particle effects
// Disable or enable cursor
cursor.disable();
cursor.enable();