Move elements along the X, Y, and Z axes.
Default: 0 for all axes
When no start value is configured for any axis, the default will be used for that axis.
Type alias for the animation group name.
Set the initial X, Y, and Z position.
import Anim.Engine.* as Engine
import Anim.Property.Translate as Translate
init : ( Model, Cmd Msg )
init =
( { animState = Engine.init [ Translate.initXYZ "animGroupName" 100 20 50 ] }
, Cmd.none
)Set the initial X and Y position.
Set the initial X and Z position.
Set the initial X position.
Set the initial Y and Z position.
Set the initial Y position.
Set the initial Z position.
Turn the AnimBuilder into a translate animation Builder for the specified animation group.
Use this to start configuring a translate animation.
myAnimation : AnimBuilder eng -> AnimBuilder eng
myAnimation =
Translate.begin
>> ... -- Configure and build the animationComplete the Builder animation configuration and return an AnimBuilder
so you can continue configuring other property animations or execute the animation with an Engine.
myAnimation : AnimBuilder eng -> AnimBuilder eng
myAnimation =
Translate.begin
>> ... -- configure the animation with from, to, duration, easing, etc.
>> Translate.end
>> ... -- continue with animationSet the starting X, Y, and Z position.
myAnimation : AnimBuilder eng -> AnimBuilder eng
myAnimation =
Translate.begin
>> Translate.fromXYZ 100 20 50
>> ... -- continue with animationSet the starting X and Y position. Z is left unchanged (or 0 if not set).
Set the starting X and Z position. Y is left unchanged (or 0 if not set).
Set the starting X position. Y and Z are left unchanged (or 0 if not set).
Set the starting Y and Z position. X is left unchanged (or 0 if not set).
Set the starting Y position. X and Z are left unchanged (or 0 if not set).
Set the starting Z position. X and Y are left unchanged (or 0 if not set).
Set the target X, Y, and Z position for the current animation group.
Set the target X and Y position. Z is left unchanged (or 0 if not set).
Set the target X and Z position. Y is left unchanged (or 0 if not set).
Set the target X position. Y and Z are left unchanged (or 0 if not set).
Set the target Y and Z position. X is left unchanged (or 0 if not set).
Set the target Y position. X and Z are left unchanged (or 0 if not set).
Set the target Z position. X and Y are left unchanged (or 0 if not set).
Move by a delta instead of to a fixed position. The end value is
current + delta, where current is the live animated position.
Only available on the Sub and WAAPI engines. Using these with any other engine results in a type error.
Move by specific amounts on the X, Y, and Z axes.
myAnimation : AnimBuilder { eng | withLiveDelta : () } -> AnimBuilder { eng | withLiveDelta : () }
myAnimation =
Translate.begin
>> Translate.byXYZ 50 -25 10
>> ... -- continue with animationMove by specific amounts on the X and Y axes. Z is unaffected.
Move by specific amounts on the X and Z axes. Y is unaffected.
Move by a specific amount on the X axis. Y and Z are unaffected.
Move by specific amounts on the Y and Z axes. X is unaffected.
Move by a specific amount on the Y axis. X and Z are unaffected.
Move by a specific amount on the Z axis. X and Y are unaffected.
📖 See Animation Timing for details.
Set the delay (milliseconds) before the animation starts.
Set the animation duration (milliseconds).
The speed represents how many Units the element moves per second.
So if the CSS Unit is Px and the speed is 100, the element will move 100 pixels per second,
likewise, if the CSS Unit is Cqw and the speed is 100, the element will move 100% of it's
container's width per second.
📖 See Easing for details.
Set the easing function for the animation.
import Motion.Easing exposing (Easing(..))
Translate.easing EaseInOut📖 See Spring for details.
Drive this property with a spring.
import Motion.Spring as Spring
Translate.spring Spring.wobblyInitialize the CSS Unit for all axes.
import Anim.Engine.Keyframe as Keyframe
import Anim.Property.Translate as Translate
import Anim.Unit as Unit
Keyframe.init
[ Translate.initX "animGroupName" 50
>> Translate.initCssUnit Cqw
]Initialize the CSS Unit for the X axis.
Initialize the CSS Unit for the Y axis.
Initialize the CSS Unit for the Z axis.
Set the CSS Unit for one or more axes. This will also affect all future animations for the associated anim group.
Set the CSS Unit for all axes.
import Anim.Property.Translate as Translate
import Anim.Unit as Unit
Translate.begin
>> Translate.cssUnit Unit.Cqw
>> ... -- configure the animationWhen using responsive units like % or Cqw, the animation automatically responds
to changes in screen or container size without extra configuration. However, when
using fixed units like Px, the animation needs to be made aware of size changes
in order to respond to them. This is done with the functions below.
📖 See Responsive Animations for patterns and examples.
Keep translate values within a range you choose. Values outside the range are clamped to the nearest boundary. An animation that is within the bounds, either mid-flight or paused, will be remapped proportionally inside the bounds.
A numeric range with min and max boundaries.
Per-axis resize ranges. Nothing leaves an axis untouched.
{ x = Just { min = 0, max = 100 }
, y = Nothing
, z = Nothing
}Apply new translate bounds for an anim group during resize.
Pass this inside an engine's onResize builder:
Sub.onResize model.animState <|
Translate.bounds "box"
{ x = Just { min = 0, max = newWidth - boxSize }
, y = Nothing
, z = Nothing
}You can set the bounds for multiple anim groups in one call:
Sub.onResize model.animState <|
Translate.bounds "box" boxBounds
>> Translate.bounds "card" cardBoundsThe engine proportionally remaps the in-flight animation onto the new range and pins its endpoints to it.
Only callable from inside an engine's onResize builder - calling it from
anywhere else results in a type error.
Keep translate values on each axis within a range you choose.
Values outside the range are clamped to the nearest boundary.
Similar to bounds, but without proportional remapping.
The range stays in effect for future animations until you Unclamp it:
update msg model =
case msg of
GotCanvas (Ok { element }) ->
let
w =
element.width
h =
element.height
( animState, cmd ) =
WAAPI.retarget model.animState <|
Translate.begin
>> Translate.clampX 0 (w - boxWidth)
>> Translate.clampY 0 (h - boxWidth)
>> Translate.end
in
( { model | animState = animState }
, cmd
)Keep the X axis translate within min and max values. If min > max the values are flipped.
Keep the Y axis translate within min and max values. If min > max the values are flipped.
Keep the Z axis translate within min and max values. If min > max the values are flipped.
Remove the X axis range for this animation group. Does nothing if no range is set.
Remove the Y axis range for this animation group. Does nothing if no range is set.
Remove the Z axis range for this animation group. Does nothing if no range is set.
Snap to a specific position, cancelling any in-flight animation on this property.
Snap target X, Y and Z values silently
Snap target X and Y values, preserving the current Z value.
Snap target X and Z values, preserving the current Y value.
Snap target X value, preserving the current Y and Z values.
Snap target Y and Z values, preserving the current X value.
Snap target Y value, preserving the current X and Z values.
Snap target Z value, preserving the current X and Y values.
Builder type for translate animations.