Search...
onComplete( )
Sets an event handler that runs when the timeline completes playing.
Description
The event handler set by calling the onComplete()
function runs when a
timeline completes playing by reaching the end.
When a timeline has been set to repeat, the event handler runs at the end of the last repetition and does not run for the preceding repetitions.
If an event handler is already set for onComplete
, setting a new event
handler overrides the one set previously.
To remove an event handler you set previously, call the onComplete()
function and pass null
for the handler
parameter.
Syntax
function onComplete(handler: Function): TimeLine
onComplete Parameters
NAME
TYPE
DESCRIPTION
handler
Function
The name of the function or the function expression to run when the timeline completes playing.
Was this helpful?
Set an event handler that runs when a timeline completes playing forwards
Copy Code
1import wixAnimationsFrontend from 'wix-animations-frontend';23let timeline = wixAnimationsFrontend.timeline();45// ...67timeline.onComplete( () => {8 // handle timeline forwards completion9 console.log("Timeline has completed playing in reverse.");10} );
Remove the event handler that runs when a timeline completes playing forwards
Copy Code
1import wixAnimationsFrontend from 'wix-animations-frontend';23let timeline = wixAnimationsFrontend.timeline();45// ...67timeline.onComplete( null );
Display a message when a timeline completes playing forwards
Copy Code
1import wixAnimationsFrontend from 'wix-animations-frontend';23let timeline = wixAnimationsFrontend.timeline();45$w.onReady( function () {6 const myImage = $w("#myImage");78 timeline9 .add( myImage, {10 "rotate": 360,11 "scale": .5,12 "duration": 100013 } )14 .add( myImage, {15 "opacity": 0,16 "duration": 100017 } )18 .onComplete( () => {19 $w("#messageText").text = "Timeline has completed playing forwards.";20 } )21 .play();22} );