Wix-Animation Module Implementation: Follow These Tips to Set It Up

Written by velo | Published 2021/04/01
Tech Story Tags: website-development | design | web-design | velo | wix | beginners | javascript | coding-with-velo

TLDR Velo is a full-stack development platform that empowers you to rapidly build, manage and deploy professional web apps. The wix-animations module contains functionality for working with a timeline. A timeline defines what animations are played on which page elements and when those are played. The following list outlines the typical process of creating and playing an animation timeline: Creating a timeline, adding animation attributes, and adding buttons for controlling timeline playback. The timeline is used to compose animations together over time.via the TL;DR App

The wix-animations module contains functionality for working with
animations. Learn more.
Guides (Additional information about this section)
Functions (Perform actions on an object)
Subcategories
Related Content

Introduction

Animation sequences are composed using a timeline. A timeline defines what animations are played on which page elements and when those animations are played.
Typical Animation Process
The following list outlines the typical process of creating and playing an animation timeline:
  • Create a new timeline using the
    timeline()
    function.
  • Add animation attributes and sequence them within the timeline using the
    add()
    function.
  • Control the playing of the timeline using the
    play()
    ,
    reverse()
    ,
    pause()
    , and
    replay()
    functions.
To use the Animations API, import
wixAnimations
from the
wix-animations
module:
import wixAnimations from 'wix-animations';

timeline( )

Creates a new animation timeline.
Description
A timeline is used to compose animations together over time. You can synchronize multiple animations on matched elements, control them as a whole, and precisely manage their timing.
Typically, after creating a new timeline, you add animation attributes and
sequence them within the timeline using the
add()
function.
Control the timeline playback using the
play()
,
reverse()
,
pause()
, and
replay()
functions.
Use the timelineOptions parameter to specify whether the timeline repeats
and how the repetitions are played.
Syntax
function timeline([timelineOptions: TimeLineOptions]): TimeLine
timeline Parameters
Create a timeline
import wixAnimations from 'wix-animations';

let timeline = wixAnimations.timeline();
Create a timeline that repeats
import wixAnimations from 'wix-animations';

let timeline = wixAnimations.timeline({"repeat": 3});
Create a timeline with options
import wixAnimations from 'wix-animations';

let timeline = wixAnimations.timeline(
  {
    "repeat": 3,
    "repeatDelay": 100,
    "yoyo": true
  }
);
Create a timeline, add animation attributes, and add buttons for controlling timeline playback
import wixAnimations from 'wix-animations';

let timeline = wixAnimations.timeline(
  {
    "repeat": 3,
    "repeatDelay": 100,
    "yoyo": true
  }
);

$w.onReady( function () {
  const myImage = $w("#myImage");

  timeline
    .add( myImage, {
      "rotate": 360,
      "scale": .5,
      "duration": 1000
    } )
    .add( myImage, {
      "opacity": 0,
      "duration": 1000
    } );

  $w("#playButton").onClick( () => {
    timeline.play();
  } );

  $w("#reverseButton").onClick( () => {
    timeline.reverse();
  } );

  $w("#pauseButton").onClick( () => {
    timeline.pause();
  } );

  $w("#replayButton").onClick( () => {
    timeline.replay();
  } );
} );
Returns
The newly created timeline.
Return Type: TimeLine

Written by velo | Velo is a full-stack development platform that empowers you to rapidly build, manage and deploy professional web apps.
Published by HackerNoon on 2021/04/01