Overview
The glass cursor provides:- Custom cursor with dot and outline elements
- Smooth delayed animation for outline
- Hover effects for interactive elements
- Responsive behavior (desktop only)
- Accessibility support (respects reduced motion preference)
Installation
The glass cursor is automatically initialized when the DOM is ready:Functions
initGlassCursor()
Initializes the glass cursor effect with custom dot and outline elements. Location:src/scripts/glass-cursor.js:2
Usage:
Minimum width of 1024px (desktop only)
If true, cursor effect is disabled
-
Checks prerequisites:
- Returns early if user prefers reduced motion
- Returns early if viewport width < 1024px
-
Creates cursor elements:
.cursor-outline- Outer ring with glass effect.cursor-dot- Inner dot
-
Sets up mouse tracking:
- Dot follows mouse instantly
- Outline follows with smooth delay
-
Adds hover effects:
- Adds
.hoverclass to interactive elements - Interactive selectors:
a, button, .tag, .accordion-header, .q-btn, input, textarea
- Adds
-
Hides default cursor:
- Sets
cursor: noneon body and all elements
- Sets
-
Handles viewport events:
- Fades out cursor when mouse leaves viewport
- Fades in cursor when mouse enters viewport
Animation Details
Smooth Following Animation
The outline follows the cursor with a smooth delay using linear interpolation:Controls the smoothness of the outline following effect. Lower values = slower following.
Cursor Positioning
Both cursor elements use CSStransform: translate(-50%, -50%) for perfect centering:
Interactive Elements
The following elements receive hover effects:| Selector | Description |
|---|---|
a | Links |
button | Buttons |
.tag | Skill tags |
.accordion-header | Accordion headers |
.q-btn | Custom buttons |
input | Input fields |
textarea | Textarea fields |
Hover State
When hovering over interactive elements:CSS Requirements
The module expects the following CSS classes to be defined:.cursor-outline
Outer ring with glass morphism effect:.cursor-dot
Inner dot:Example Usage
Manual Initialization
Add Custom Interactive Elements
To add hover effects to custom elements after initialization:Accessibility
The cursor effect respects accessibility preferences:Browser Support
Required Features:requestAnimationFrame- CSS
backdrop-filterfor glass effect - CSS transforms
- Media queries
Debugging
The module includes console logging for initialization:- Initialization confirmation
- Reduced motion detection
- Screen width detection
- Element creation confirmation
Performance Considerations
- Uses
requestAnimationFramefor smooth 60fps animation pointer-events: noneprevents cursor elements from blocking interactions- Passive event listener for viewport events (when supported)
- Minimal DOM manipulation (only position updates)