A powerful, lightweight, and modular JavaScript library for creating custom mouse cursors and trail effects in web applications. Transform your user experience with smooth-following trails and customizable cursor styles.
- ๐จ Modular API: Each property has its own method for maximum flexibility
- ๐ฑ๏ธ Multiple Trail Types: Circle, Square, Triangle, Star, Dot (filled and hollow variants)
- ๐ฏ Custom Cursors: Built-in cursors, crosshair generator, and image cursor support
- โ๏ธ Full Customization: Size, thickness, color, delay, and custom CSS styling
- ๐ Overlapping Trails: Create multiple trails that run simultaneously
- ๐ Method Chaining: Combine multiple effects effortlessly
- ๐ Performance Optimized: Smooth 60fps animations with requestAnimationFrame
- ๐ป CLI Help: Built-in command-line help with
cursorlab help
- ๐ฑ Universal Compatibility: Works in browsers and Node.js environments
- ๐ผ Zero Dependencies: Lightweight and self-contained
npm install cursorlab
# Try the interactive demo!
cursorlab demo
<!-- Include in HTML -->
<script src="node_modules/cursorlab/browser.js"></script>
<script>
// Set a circle trail with custom properties
CursorLab.setCursorTrail('circle')
.setColor('#ff0000')
.setSize(20)
.setThickness(3)
.trailDelay(0.1)
.startTrail();
</script>
// Node.js / ES6 Module
const CursorLab = require('cursorlab');
// Create instance for advanced control
const cursor = new CursorLab();
cursor.setCursorTrail('star')
.setColor('#00ff00')
.setSize(25)
.startTrail();
CursorLab uses a modular approach where each property has its own method. This allows for maximum flexibility and clear, readable code.
Set the trail shape that follows your cursor.
Available Types:
'circle'
- Hollow circle'circle-filled'
- Filled circle'square'
- Hollow square'square-filled'
- Filled square'triangle'
- Triangle shape'star'
- Star shape'dot'
- Small filled circle
CursorLab.setCursorTrail('circle');
CursorLab.setCursorTrail('star');
Control the trail dimensions.
// Single parameter - sets radius for circles/dots, or size for squares/stars
CursorLab.setSize(20);
// Two parameters - sets width and height independently
CursorLab.setSize(30, 20); // 30px wide, 20px tall
Set border thickness for hollow shapes.
CursorLab.setThickness(1); // Thin border
CursorLab.setThickness(5); // Thick border
Set the trail color using any CSS color format.
CursorLab.setColor('#ff0000'); // Hex
CursorLab.setColor('red'); // Named color
CursorLab.setColor('rgb(255,0,0)'); // RGB
CursorLab.setColor('hsl(0,100%,50%)'); // HSL
Control how quickly the trail follows the cursor (0.01 = fast, 0.3 = slow).
CursorLab.trailDelay(0.05); // Fast following
CursorLab.trailDelay(0.1); // Normal speed
CursorLab.trailDelay(0.3); // Slow following
Begin the trail animation. Call this after setting up your trail properties.
CursorLab.setCursorTrail('circle').setColor('blue').startTrail();
Change the actual cursor appearance.
Built-in Cursors:
CursorLab.setCustomCursor('grab');
CursorLab.setCustomCursor('copy');
CursorLab.setCustomCursor('none'); // Hide cursor
Custom Crosshair:
// setCustomCursor('crosshair', thickness, length)
CursorLab.setCustomCursor('crosshair', 2, 15);
CursorLab.setCustomCursor('crosshair', 4, 25); // Thicker, longer
Image Cursors:
// Use any image as cursor
CursorLab.setCustomCursor('url(path/to/cursor.png), auto');
CursorLab.setCustomCursor('url(data:image/png;base64,iVBOR...), auto');
Apply advanced CSS styling.
Object Format:
CursorLab.setCustomStyle({
cursor: 'none',
'pointer-events': 'auto'
});
CSS String Format:
CursorLab.setCustomStyle(`
.cursorlab-trail {
filter: blur(2px) !important;
opacity: 0.7 !important;
animation: pulse 1s infinite !important;
}
@keyframes pulse {
0%, 100% { transform: translate(-50%, -50%) scale(1); }
50% { transform: translate(-50%, -50%) scale(1.2); }
}
`);
All methods return this
, enabling powerful method chaining:
// Basic chaining
CursorLab.setCursorTrail('circle')
.setColor('#ff0000')
.setSize(20)
.startTrail();
// Complex combination
CursorLab.setCursorTrail('star')
.setColor('#9b59b6')
.setSize(25)
.setThickness(3)
.trailDelay(0.08)
.setCustomCursor('grab')
.setCustomStyle({cursor: 'none'})
.startTrail();
// Multiple effects
const cursor = new CursorLab();
cursor.setCursorTrail('triangle')
.setColor('#e74c3c')
.setSize(30, 25) // width, height
.trailDelay(0.12)
.setCustomCursor('crosshair', 3, 20)
.startTrail();
// Create new trail (replaces any existing trail)
CursorLab.setCursorTrail('circle').setColor('#ff0000').setSize(25).startTrail();
// Remove all trails (keeps cursor changes)
CursorLab.setDefault();
// Reset cursor to original
CursorLab.setNormalCursor();
// Remove everything and clean up
CursorLab.destroy();
// Check if any trail is active
if (CursorLab.isActive()) {
console.log('Trails are running');
}
CursorLab.setCursorTrail('star')
.setColor('#ff00ff')
.setSize(30)
.trailDelay(0.06)
.setCustomCursor('crosshair', 2, 18)
.setCustomStyle(`
.cursorlab-trail {
animation: rainbow 2s infinite !important;
}
@keyframes rainbow {
0% { filter: hue-rotate(0deg); }
100% { filter: hue-rotate(360deg); }
}
`)
.startTrail();
CursorLab.setCursorTrail('square')
.setColor('#f39c12')
.setSize(22)
.setThickness(4)
.trailDelay(0.15)
.setCustomStyle(`
.cursorlab-trail {
animation: spin 1s linear infinite !important;
}
@keyframes spin {
from { transform: translate(-50%, -50%) rotate(0deg); }
to { transform: translate(-50%, -50%) rotate(360deg); }
}
`)
.startTrail();
// Small fast dot
CursorLab.setCursorTrail('dot')
.setSize(8)
.setColor('#1abc9c')
.trailDelay(0.03)
.startTrail();
// Large slow circle
CursorLab.setCursorTrail('circle')
.setSize(40)
.setThickness(2)
.setColor('#e74c3c')
.trailDelay(0.25)
.startTrail();
// Uses a global instance automatically
CursorLab.setCursorTrail('circle').setColor('red').startTrail();
CursorLab.setDefault(); // Reset the trail
// Create separate instances for independent control
const cursor1 = new CursorLab();
const cursor2 = new CursorLab();
cursor1.setCursorTrail('circle').setColor('blue').startTrail();
cursor2.setCursorTrail('star').setColor('red').startTrail();
Method | Parameters | Description |
---|---|---|
setCursorTrail(type) |
type: string |
Set trail shape |
setSize(size) |
size: number |
Set uniform size |
setSize(width, height) |
width: number, height: number |
Set dimensions |
setThickness(thickness) |
thickness: number |
Set border thickness |
setColor(color) |
color: string |
Set trail color |
trailDelay(delay) |
delay: number |
Set follow speed |
startTrail() |
- | Begin trail animation |
Method | Parameters | Description |
---|---|---|
setCustomCursor(type) |
type: string |
Set CSS cursor |
setCustomCursor('crosshair', thickness, length) |
thickness: number, length: number |
Custom crosshair |
setCustomCursor(imageUrl) |
imageUrl: string |
Image cursor |
setCustomStyle(styles) |
styles: object|string |
Custom CSS |
Method | Parameters | Description |
---|---|---|
setDefault() |
- | Remove trail |
setNormalCursor() |
- | Reset cursor |
destroy() |
- | Clean up everything |
isActive() |
- | Check if active |
CursorLab includes a built-in command-line interface for quick reference:
# After installation
npm install cursorlab
# Get comprehensive help
cursorlab help
# Open interactive demo in browser
cursorlab demo
# Check version
cursorlab version
The CLI provides:
- Complete API documentation
- Method chaining examples
- Browser and Node.js examples
- Performance tips and best practices
- Interactive demo with live controls -
cursorlab demo
Perfect for quick reference while coding!
- Use
trailDelay(0.1)
or higher for better performance on slower devices - Avoid very complex CSS animations in
setCustomStyle()
- Call
destroy()
when removing the trail to prevent memory leaks
- Combine trails with CSS filters:
blur()
,drop-shadow()
,brightness()
- Use CSS animations for rotating, pulsing, or color-changing effects
- Create visual depth with different colors and delays
- Image cursors work best with PNG files under 32x32 pixels
- Use data URLs for embedded cursor images
- Test crosshair cursors across different browsers for consistency
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see the LICENSE file for details.