onStart( )
Sets an event handler that runs when the timeline starts playing.
Description
The event handler set by calling the onStart()
function runs when a
timeline starts playing from the beginning.
This happens when:
- The
play()
function is called on a timeline that has not been played yet. - The
replay()
function is called, regardless of the timeline state, since it replays the timeline from its beginning.
When a timeline has been set to repeat, the event handler runs at the beginning
of the first repetition and does not run for each successive repetition. To set
an event handler that runs when a timeline repeats, use the onRepeat()
function.
If an event handler is already set for onStart
, setting a new event
handler overrides the one set previously.
To remove an event handler you set previously, call the onStart()
function and pass null
for the handler
parameter.
Syntax
function onStart(handler: Function): TimeLine
onStart Parameters
NAME
TYPE
DESCRIPTION
The name of the function or the function expression to run when the timeline starts playing.
Was this helpful?
1import wixAnimationsFrontend from 'wix-animations-frontend';23let timeline = wixAnimationsFrontend.timeline();45// ...67timeline.onStart( () => {8 // handle timeline start9 console.log("Timeline has started.");10} );
1import wixAnimationsFrontend from 'wix-animations-frontend';23let timeline = wixAnimationsFrontend.timeline();45// ...67timeline.onStart( null );
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 .onStart( () => {19 $w("#messageText").text = "Timeline has started.";20 } )21 .play();22} );