Hover Glow Effect For Astro
A pointer glow that follows the cursor over any pattern.
Installation
bunx --bun shadcn@latest add @gnostic/hover-glownpx shadcn@latest add @gnostic/hover-glowpnpm dlx shadcn@latest add @gnostic/hover-glowCopy the files
src/components/patterns/hover-glow/hover-glow.astrosrc/components/patterns/hover-glow/hover-glow.tssrc/components/patterns/hover-glow/index.tssrc/components/patterns/hover-glow/types.ts
Usage
HoverGlow is the positioned container. Move the pointer over it to show
the glow. The preview above has no pattern. Give text relative z-10 when
the text must stay above the glow.
import { HoverGlow } from "@/components/patterns/hover-glow"
<HoverGlow class="h-72">
<p class="relative z-10">Move the pointer</p>
</HoverGlow>
The glow color defaults to a 40 percent mix of var(--color-primary), so
a plain spotlight stays soft. A masked pattern is small, so give it more
alpha or the shapes disappear. glowSize sets the radius in pixels.
The glow fades out when the pointer leaves the container or the window loses focus.
Set maskImage to one tile of a pattern and maskSize to the tile size
when the glow should follow that pattern. The color shows only inside the
tile. Leave the pattern out of the slot to hide it until the pointer arrives.
Put the same pattern in the slot when it should stay visible and the glow
should only color its shape. Leave the mask unset to paint the glow across
the whole area.
Dots use a small circle for each tile:
<HoverGlow
class="h-72"
maskImage="radial-gradient(circle, black 1.5px, transparent 1.5px)"
maskSize="18px 18px"
/>
A grid uses one horizontal line and one vertical line. 60px matches the
default grid cell:
<HoverGlow
class="h-72"
maskImage="linear-gradient(black 1px, transparent 1px), linear-gradient(90deg, black 1px, transparent 1px)"
maskSize="60px 60px"
/>
Dot Pattern with Glow keeps the base dots and uses the dot mask, so the dots stay visible and the glow colors them.
Examples
Reveal on hover
This example has no base pattern. The dot mask is the only pattern.
API Reference
HoverGlowProps
glowColor?string
CSS color of the glow. Use the color's alpha value to set the glow opacity. The default keeps the glow soft.
string"color-mix(in oklch, var(--primary) 72%, transparent)"glowSize?number
Radius of the glow, in pixels.
number96maskImage?string
CSS `mask-image` for the glow layer. Use a repeating mask so the glow shows only inside a pattern shape.
string"none"maskSize?string
CSS `mask-size` for the glow layer.
string"auto"maskPosition?string
CSS `mask-position` for the glow layer.
string"center"See the registry source for the component source.