Overview
The Glass Cursor feature replaces the default cursor with a custom glassmorphism design consisting of two elements: a precise dot and a smooth-following outline with blur effects.Implementation
Implemented insrc/scripts/glass-cursor.js with device and accessibility checks.
Initialization Checks
Reduced Motion Check
src/scripts/glass-cursor.js:4-7
Device Width Check
src/scripts/glass-cursor.js:10-13
Reasoning: Custom cursors are disabled on mobile/tablet devices where cursor interaction doesn’t apply.
Cursor Elements
Creating DOM Elements
src/scripts/glass-cursor.js:18-29
Element Structure
- cursor-dot: Small, instant-following dot
- cursor-outline: Larger outline with delayed follow and glassmorphism effects
Position Tracking
Mouse Position Variables
src/scripts/glass-cursor.js:33-36
Mouse Movement Handler
src/scripts/glass-cursor.js:39-46
Key Detail: The dot follows the cursor instantly for precise interaction feedback.
Smooth Follow Animation
Animation Loop
src/scripts/glass-cursor.js:49-61
How it works:
- Uses linear interpolation (lerp) for smooth following
delay = 0.12creates a natural lag effectrequestAnimationFrameensures smooth 60fps animation
Lerp Formula
delay = 0.12, the outline closes 12% of the distance each frame.
Interactive Hover Effects
Adding Hover States
src/scripts/glass-cursor.js:64-77
Interactive Elements:
- Links (
<a>) - Buttons (
<button>) - Tags (
.tag) - Accordion headers
- Quick question buttons
- Form inputs
Hiding Default Cursor
System Cursor Removal
src/scripts/glass-cursor.js:79-84
Note: Setting cursor: none on all elements prevents any default cursor from appearing.
Viewport Behavior
Mouse Leave/Enter Handling
src/scripts/glass-cursor.js:86-95
Purpose: Hides custom cursor when mouse leaves the viewport, prevents cursor artifacts at screen edges.
CSS Styling
Cursor Dot Styles
- Fixed positioning for consistent placement
transform: translate(-50%, -50%)centers on cursor positionpointer-events: noneprevents blocking interactions- Shrinks on hover for cleaner look
Cursor Outline Styles
backdrop-filter: blur(2px)creates glass effect- Semi-transparent background
- Expands and intensifies on hover
Initialization
DOM Ready Check
src/scripts/glass-cursor.js:98-104
Export
src/scripts/glass-cursor.js:106
Performance Considerations
Optimization Techniques
- requestAnimationFrame: Syncs with browser refresh rate (60fps)
- CSS Transforms: Hardware-accelerated positioning
- pointer-events: none: Prevents cursor from blocking interactions
- Conditional Loading: Only loads on desktop devices
Performance Metrics
- Frame Rate: Maintains 60fps on modern devices
- CPU Usage: Minimal due to hardware acceleration
- Memory: ~2KB for cursor elements
Customization
Adjusting Follow Speed
0.08 (fast) to 0.20 (slow)
Changing Cursor Size
Adding More Interactive Elements
Browser Compatibility
| Feature | Browser Support |
|---|---|
backdrop-filter | Chrome 76+, Safari 9+ |
requestAnimationFrame | All modern browsers |
| CSS transforms | All modern browsers |
Accessibility
Reduced Motion
The cursor is automatically disabled when users prefer reduced motion:Screen Readers
- Custom cursor is purely visual
- Does not interfere with screen reader functionality
pointer-events: noneensures normal interaction behavior
Troubleshooting
Cursor Not Appearing
- Check browser console for initialization messages
- Verify screen width is >= 1024px
- Ensure reduced motion is not enabled
- Check CSS is loaded properly
Cursor Feels Laggy
- Increase
delayvalue (e.g.,0.15) - Check for other heavy animations running
Hover States Not Working
- Verify element selector in
interactiveElements - Check CSS
.hoverclasses are defined - Ensure elements aren’t being dynamically added after initialization
Best Practices
- Always include fallback: Default cursor should work if custom cursor fails
- Respect user preferences: Check for reduced motion
- Test on multiple devices: Ensure proper desktop-only loading
- Monitor performance: Use Chrome DevTools to check frame rate
- Provide clear hover feedback: Make interactive elements obvious