createMotionPath()
Creates properties for animating an element along an SVG path with automatic rotation.Syntax
Parameters
CSS selector, SVG path element, or any SVG geometry element to follow
Offset along the path (normalized 0-1). Use negative values to start before the path beginning.
Returns
An object with properties for motion path animation:
translateX: X position along the pathtranslateY: Y position along the pathrotate: Rotation angle tangent to the path (in degrees)
Examples
Basic Motion Path
Motion Path Without Rotation
Motion Path with Offset
Staggered Motion Path
Notes
- Works with any SVG geometry element:
<path>,<circle>,<rect>,<ellipse>,<line>,<polyline>,<polygon> - Automatically handles coordinate transformation for both SVG and HTML elements
- The
rotateproperty aligns the element tangent to the path direction - Uses
getPointAtLength()andgetTotalLength()SVG APIs internally
Source
Defined in:/home/daytona/workspace/source/src/svg/motionpath.js:80
createDrawable()
Creates drawable proxies for SVG elements with animated stroke drawing effects.Syntax
Parameters
CSS selector, SVG element(s), or array of elements to make drawable
Starting position of the stroke (0-1 range)
Ending position of the stroke (0-1 range)
Returns
Array of proxied SVG elements with a special
draw attribute for animation.The draw attribute accepts space-separated values: "start end"0 0: Nothing drawn0 1: Fully drawn0 0.5: Half drawn from start0.5 1: Half drawn from middle to end
Examples
Basic Draw Animation
Reveal Effect
Write and Erase Effect
Partial Draw Animation
How It Works
ThecreateDrawable() function:
- Sets
pathLength="1000"on the SVG element for normalized calculations - Returns a proxy that intercepts
setAttribute('draw', value)calls - Converts the
drawvalue tostroke-dashoffsetandstroke-dasharray - Handles
stroke-linecapautomatically (switches tobuttwhen start equals end) - Accounts for
vector-effect="non-scaling-stroke"and CTM transforms
Notes
- Works with any SVG geometry element with a stroke
- Does not modify the original SVG structure, only CSS properties
- Compatible with responsive/scaled SVG elements
- Automatically handles stroke linecap for smooth animations
Source
Defined in:/home/daytona/workspace/source/src/svg/drawable.js:111
morphTo()
Creates a morph animation value that transforms one SVG shape into another.Syntax
Parameters
CSS selector or SVG element to morph into. Supports
<path>, <polygon>, and <polyline> elements.Controls the number of interpolation points based on path length.
- Higher values = smoother morph but more points
0= Use raw path data (no interpolation)- Typical range:
0.1to1
Returns
A function value that generates morph data for the animation:
Examples
Basic Morph
Morph with Custom Precision
Polygon Morph
Morph with Timeline
Bidirectional Morph
How It Works
- Calculates the total length of both source and target paths
- Generates interpolation points along both paths based on
precision - Creates matching point arrays for smooth morphing
- Returns path data as
[fromPath, toPath]for animation - Caches morph data on the element for consistent animations
Supported Elements
<path>(animatesdattribute)<polygon>(animatespointsattribute)<polyline>(animatespointsattribute)
Notes
- Both shapes must be the same element type
- The function interpolates points to ensure smooth morphing
- Higher precision values improve visual quality but increase computation
- Morph data is cached to maintain consistency across multiple animations
- For best results, use shapes with similar complexity
Source
Defined in:/home/daytona/workspace/source/src/svg/morphto.js:25