Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Backgrounds

  • DotPattern
  • GridPattern
  • StripedPattern
  • Spotlight
  • FadeMask
  • RetroGrid
  • Ripple
  • Meteors
  • Aurora
  • Particles
  • FlickeringGrid
  • WavyBackground
  • Silk
  • Iridescence
  • Threads
  • Orb
  • LiquidChrome
  • Balatro
  • Ballpit
  • Beams
  • ColorBends
  • DarkVeil
  • Dither
  • DotField
  • EvilEye
  • FaultyTerminal
  • Ferrofluid
  • FloatingLines
  • Galaxy
  • GradientBlinds
  • Grainient
  • GridDistortion
  • GridMotion
  • GridScan
  • Hyperspeed
  • LetterGlitch
  • Lightfall
  • Lightning
  • LightPillar
  • LightRays
  • LineWaves
  • LiquidEther
  • PixelBlast
  • PixelSnow
  • Plasma
  • PlasmaWave
  • Prism
  • PrismaticBurst
  • Radar
  • RippleGrid
  • ShapeGrid
  • SideRays
  • SoftAurora

Overlay Effects

  • BorderBeam
  • ShineBorder
  • GlareHover
  • Lens
  • AnimatedBeam
  • OrbitingCircles
  • ProgressiveBlur
  • CardSpotlight
  • Reveal
  • Antigravity
  • BlobCursor
  • ClickSpark
  • Crosshair
  • ElectricBorder
  • GhostCursor
  • GradualBlur
  • ImageTrail
  • LaserFlow
  • MagicRings
  • Magnet
  • MagnetLines
  • MetaBalls
  • MetallicPaint
  • OrbitImages
  • PixelTrail
  • PixelTransition
  • Ribbons
  • ShapeBlur
  • SplashCursor
  • StarBorder
  • StickerPeel
  • TargetCursor
  • Cubes
  • Tilt
  • BorderGlow
  • GlassIcons
  • GlassSurface
  • Lanyard
  • ModelViewer
  • FluidGlass

MagnetLines

magnet-lines

Rotates a field of line segments toward the pointer.

Usage

Basic usage

9×9 grid of line segments, with each line pointing towards the mouse in real time like a compass.

tsx
<MagnetLines containerSize="16rem" lineColor="var(--color-foreground)" />

Fine mesh

Increase rows/columns and narrow the line width to obtain a finer magnetic line field.

tsx
<MagnetLines
  rows={13}
  columns={13}
  containerSize="16rem"
  lineWidth="0.4rem"
  lineHeight="2rem"
  lineColor="var(--color-chart-1)"
/>

Sparse thick lines

Fewer rows and columns + thicker line segments, with brand colors to enhance visual decoration.

tsx
<MagnetLines
  rows={6}
  columns={6}
  containerSize="16rem"
  lineWidth="0.8rem"
  lineHeight="3rem"
  lineColor="var(--color-primary)"
/>

Initial angle

baseAngle determines the rest angle of all line segments when the pointer does not move.

tsx
<MagnetLines
  baseAngle={45}
  containerSize="16rem"
  lineColor="var(--color-chart-2)"
/>

When to Use

Lay out a grid of thin line segments and turn each line segment to point to the mouse in real time, creating a magnetic field/compass-style minimalist interactive decoration. It is a lightweight solution of pure CSS transform (without WebGL). Compared with WebGL-heavy backgrounds such as GhostCursor / LaserFlow, it is lighter and more suitable for small graphic embellishments. The container is square and occupies 80vmin by default.

Import

ts
import { MagnetLines } from "@hulianui/ui"

Props

NameTypeDefaultDescription
rowsnumber9Number of grid rows; rows × columns determines the total number of segments
columnsnumber9Number of grid columns
containerSizestring"80vmin"Container size (any CSS length), square, with segments spread equally across it
lineColorstringvar(--color-foreground)Line segment color, light and dark theme; any CSS color string can be used
lineWidthstring"1vmin"Single line segment width (any CSS length)
lineHeightstring"6vmin"Single line segment height (any CSS length)
baseAnglenumber-10Initial rest angle (degrees); maintain this angle when the pointer does not move or reduces-motion
classNamestring-Additional class name for the root container
styleCSSProperties-Inline styles for the root container, merged after the computed grid styles

Usage Guidelines

  • rows × columns is the number of DOM line segment nodes (default 81). Too large a grid will drag down the rendering. Control the density as needed.
  • All line segments under reduced-motion are fixed at baseAngle and no longer follow the mouse.

Related

BorderBeam · ShineBorder · GlareHover · Lens · AnimatedBeam · OrbitingCircles

Playground

<div className="relative flex h-72 items-center justify-center overflow-hidden rounded-xl"
     style={{ background: "oklch(0.14 0.02 255)" }}>
  <MagnetLines
    rows={9}
    columns={9}
    baseAngle={-10}
    containerSize="16rem"
    lineColor="var(--color-foreground)"
  />
</div>
PreviousMagnetDecorationNextMetaBalls

On this page

  • Usage
  • Documentation
    • When to Use
    • Import
    • Props
    • Usage Guidelines
    • Related
  • Playground