Animated Beam

An SVG beam connecting elements with animation.

API

Prop NameTypeDefaultDescription
classstring""Additional CSS classes to apply to the component for customization.
containerRefHTMLElementN/AReference to the container element where the beam is rendered.
fromRefHTMLElementN/AReference to the starting element from which the beam originates.
toRefHTMLElementN/AReference to the ending element where the beam points to.
curvaturenumber0Controls the curvature of the beam; higher values create a more curved path.
reversebooleanfalseReverses the animation direction of the beam if set to true.
pathColorstring"gray"Color of the beam's path.
pathWidthnumber2Stroke width of the beam's path.
pathOpacitynumber0.2Opacity of the beam's path.
gradientStartColorstring"#FFAA40"Starting color of the beam's gradient animation.
gradientStopColorstring"#9C40FF"Ending color of the beam's gradient animation.
delaynumber0Delay before the beam's animation starts, in seconds.
durationnumberRandom between 4–7 sDuration of the beam's animation cycle, in seconds.
startXOffsetnumber0Horizontal offset for the beam's starting point.
startYOffsetnumber0Vertical offset for the beam's starting point.
endXOffsetnumber0Horizontal offset for the beam's ending point.
endYOffsetnumber0Vertical offset for the beam's ending point.

Example

Double-sided beam.

Component Code

You can copy and paste the following code to create this component:

AnimatedBeam.vue

Features

  • Dynamic Beam Drawing: Automatically renders a beam between two specified elements on the page.
  • Smooth Animation: Features a gradient animation that flows along the beam's path for a visually engaging effect.
  • Customizable Appearance: Easily adjust color, width, opacity, and curvature to match your design requirements.
  • Responsive Updates: The beam adjusts its position and size in response to window resizing and element repositioning.
  • Flexible Animation Control: Customize the animation's duration, delay, and direction for precise timing.

Credits