Custom Components
Text Weight Hover
Text Weight Hover
Instructions
Overview
Add an interactive text effect that dynamically changes font weight as users hover their cursor over text, creating a magnetic-like interaction.
Getting Started
Quick Start
- Click the Copy Component button on the top of the page.
- Paste the component into your Webstudio site.
Manual Start
- Add the Script: Copy and paste this code into your website's after the component:
[code-block]<script type="module" src="https://drevo.b-cdn.net/Library/Custom%20Components/Text%20Weight%20Hover/text-weight-hover-v1.0.js"></script>[/code-block]
- Add the Attribute: Add the
dv-weight-hover-effect
attribute to any text element:<h2 dv-weight-hover-effect="400-to-700">Hover over me</h2>
Customization Options
Font Weight Range
- Use the format
initial-to-max
to define the font weight range - Example:
dv-weight-hover-effect="300-to-900"
- Valid font weights typically range from 100 to 900
How It Works
- The component splits text into individual characters
- As your cursor moves over the text, each character's font weight changes based on:
- Distance from the cursor
- The defined weight range
- Characters closest to the cursor receive the maximum weight
- Characters farther away maintain the initial weight
- When the cursor leaves, all characters return to the initial weight
Best Practices
- Use with variable fonts for the smoothest transitions
- Choose appropriate weight ranges for your font family
- Works best with headings and short text blocks
- Ensure sufficient contrast between initial and maximum weights
- Test with different font families to find the best effect
Notes
- The effect has a 100-pixel radius of influence around the cursor
- Transitions are optimized for performance using CSS custom properties
- Compatible with all modern browsers that support CSS custom properties