CSS Dev Conf, San Antonio - October 18, 2016
See the Pen Simple animation examples by Dan Wilson (@danwilson) on CodePen.
Bouncing Ball
Cartoon Animation, Preston Blair
Comparison of web animation techniques from Sparkbox
See the Pen Sing along: Deep in the Heart by Dan Wilson (@danwilson) on CodePen.
See the Pen Inside Out DVD Menu by Dan Wilson (@danwilson) on CodePen.
SMIL: animateMotion
Specify a path, duration, iteration count, rotation
See the Pen Motion Path with SVG by Dan Wilson (@danwilson) on CodePen.
See the Pen Learning SVG animation by Fabio (@FabioG) on CodePen.
@guttentagSee the Pen Escher's Floating Point Waterfall by Adam Guttentag (@guttentag) on CodePen.
See the Pen Demo for autoRotate true/false by Sarah Drasner (@sdras) on CodePen.
Sarah Drasner
See the Pen Follow SVG Path - anime.js by Julian Garnier (@juliangarnier) on CodePen.
Julian Garnier
See the Pen Motion Path RAF demo by Dan Wilson (@danwilson) on CodePen.
Article: Animating objects over a curved path
but isn't this CSS Dev Conf?
Three options to discuss
.mover-y {
will-change: transform;
animation: y 2s infinite ease-out alternate;
}
.mover-x {
will-change: transform;
background: #45b8c9;
width: 2rem; height: 2rem; border-radius: 50%;
animation: x 2s infinite ease-in alternate;
}
@keyframes x {
100% { transform: translateX(300px); }
}
@keyframes y {
100% { transform: translateY(300px); }
}
Moving along a curved path in CSS with layered animation by Tobias Ahlin
See the Pen Sing along with the bouncing ball v2 by Dan Wilson (@danwilson) on CodePen.
.mover-z { /*grandparent*/
will-change: transform;
animation: z 2s infinite ease-in-out alternate;
}
@keyframes z {
50% { transform: translateZ(-200px); }
}
.mover-y { /*parent*/
will-change: transform;
animation: y 2s infinite ease-out alternate;
}
.mover-x {
will-change: transform;
background: #45b8c9;
width: 2rem; height: 2rem; border-radius: 50%;
animation: x 2s infinite ease-in alternate;
}
@keyframes x {
100% { transform: translateX(300px); }
}
@keyframes y {
100% { transform: translateY(300px); }
}
See the Pen Varying Y + Linear X Easings by Dan Wilson (@danwilson) on CodePen.
See the Pen Confetti by Dan Wilson (@danwilson) on CodePen.
As much fun as the previous method is...
It's not actually this talk's focus...
Take the benefits of SVG, JS, and CSS animation
Let the other methods have those benefits as well
MDN Docs for Web Animations API from Rachel Nabors
SVG already has a proven way to animate along a path
See the Pen CSS Motion Path Spiral CSSDC by Dan Wilson (@danwilson) on CodePen.
Roots in the Web Animations spec
Expose animation methods previously confined to SVG to the DOM via CSS and JS
Pieces supported in Chrome and Opera
New pieces making their way to Chrome Canary under a flag
motion-path
defines the path to follow
motion-offset
defines the position on the path
motion-rotation
defines rotation along the path
.mover {
motion-path: path("M 100,100 Q 200,50 300,100");
motion-rotation: auto;
animation: follow-path 2s 0s infinite alternate ease-in-out;
}
@keyframes follow-path {
100% { motion-offset: 100%; }
}
Example
Still Early
Play
Experiment
Know it will change
It changed!
motion-path
→ offset-path
motion-offset
→ offset-distance
motion-rotation
→ offset-rotation
offset-position
offset-anchor
CSS Dev Conf, San Antonio - October 18, 2016
Motion Path and Round Display specs had overlap
Several use cases for Motion Path without motion
We will cover support as we go
Focusing on latest spec
offset-path
path()
url()
CSS Basic Shapes
angles*
offset-path: path()
.mover {
offset-path: path("M 100,100 L 200,200");
}
What you find in an SVG path d
attribute
<svg>
<path d="M 100,100 L 200,200" stroke-width="1"/>
</svg>
Chrome 46+/Opera 33+ (as motion-path), Chrome Canary 56+ (as offset-path)
Can be intimidating
Commands to move, Commands to draw
M 100,100 L 200,200
SVG Pocket Guide: The path Element
CSS Tricks: The SVG path Syntax: An Illustrated Guide
Or... export an SVG and copy the values
offset-path: url()
<svg>
<path d="M 100,100 L 200,200" id="best-offset-path"/>
</svg>
.mover {
offset-path: url(#best-offset-path);
}
Similar to path()
, but SVG is already in document
offset-path
with CSS ShapesYou've likely heard about these at the conference already
Can flow text around non-rectangles
Can use with clip
s
See the Pen Basic Shapes Basics by Dan Wilson (@danwilson) on CodePen.
offset-path
with CSS Shapescircle()
, ellipse()
, polygon()
, etc.
offset-path: circle(20px); //radius
offset-path: ellipse(20px 30px); //x-radius y-radius
offset-path: polygon(0% 20%, 50% 0, 100% 20%, 100% 80%, 50% 100%, 0% 80%); //hexagon
No support yet
offset-path
SupportChrome and Opera only in 2016
See the Pen CSS Motion Path value types by Dan Wilson (@danwilson) on CodePen.
Only path()
at the moment
Shapes and URLs can be converted to path, though
offset-distance
Any length value
To travel along the path, go from 0% to 100%
Oh... and paths don't have to be continuous
See the Pen CSS Motion Path with Gaps by Dan Wilson (@danwilson) on CodePen.
offset-distance
Does not have to move
See the Pen Motion Path Infinity (2016 Spec) by Dan Wilson (@danwilson) on CodePen.
Chrome 46+/Opera 33+ (as motion-offset), Chrome Canary 56+ (as offset-distance)offset-rotation
Which way does the object "face" along the path
auto
(the default value) will follow the path
Can specify an angle for a fixed direction
Can also combine them to follow the path + an offset angle
offset-rotation
See the Pen Offset Rotation Values by Dan Wilson (@danwilson) on CodePen.
Chrome 46+/Opera 33+ (as motion-offset), Chrome Canary 56+ (as offset-distance)Use @supports
to check for support
See the Pen Photo Sharr (CSS Motion Path Demo) by Dan Wilson (@danwilson) on CodePen.
Spec for round surfaces, such as watches
Polar coordinates
Containing elements
offset-path: <angle>
.item-container {
width: 500px;
height: 500px;
}
.item {
offset-path: 30deg; //might have more special syntax
offset-distance: 50%;
}
No support yet
offset-position
Starting position of the path
No support yetoffset-anchor
Defines the point that connects to the path
No support yetPolyfill Demos show the positioning benefits
Don't forget spec is not finalized... even offset
could be renamed again
Minimal support only in Blink browsers
Multi Device World...
See the Pen Motion Path Options: Fixed Dimensions by Dan Wilson (@danwilson) on CodePen.
See the Pen Motion Path Options: Responsive(ish) by Dan Wilson (@danwilson) on CodePen.
Likely something where containing elements with a viewBox
property could help
viewBox
does not exist yet in CSS
Well Dan (or is it Daniel?)... Animating along a path sounds fun, but I still don't see why I should learn anything about this motion - I mean offset - path. It's barely supported, and has responsive issues, and will take forever to make it into any other browsers, and it will probably change a bit more, and I need to support Android several versions back, and when will my iPhone do this? And why hasn't the Surface Phone come out yet?
Did you see the other things that slipped in here?
Path/Shapes syntax is appearing in many places in CSS
Get in early & help form final spec
Be creative with just an object and a path
And maybe learn the Web Animations API! (and ponder how this will conflict with its offset
keyword)
Slides: https://danielcwilson.com/talks/2016/motionpath
CodePen: @danwilson
Twitter: @dancwilson
Yes... I was inconsistent with my usernames. I've learned my lesson for the future.
Also find me on slack.animationatwork.com