Custom Components
Text Weight Hover
Live Preview

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

  1. Click the Copy Component button on the top of the page.
  2. Paste the component into your Webstudio site.

Manual Start

  1. 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]

  1. 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>

text weight hover effect attributes

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

  1. The component splits text into individual characters
  2. As your cursor moves over the text, each character's font weight changes based on:
    • Distance from the cursor
    • The defined weight range
  3. Characters closest to the cursor receive the maximum weight
  4. Characters farther away maintain the initial weight
  5. 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