# Animations

## Overview

Animations serve to animate a Web Control's transition from one state to another, through its styling properties.

While styling properties are static by default, they can also be defined in terms of variables that change according to user input or information from external systems. Changes to the values of such variables are reflected as changes in the appearance of the Web Control, and applying animations smoothens these transitions.

Web Controls that allow animated style changes in this way will have an **Animations** section in their associated Inspector. This is where you can define Transition Types and Transition Times.

### Transition Types

There are eight types of stylistic changes that can be animated:

* Margin
* Padding
* Dimensions
* Font
* Background
* Border
* Rounded Corners
* Shadow

Animations will be applied only to changes in the designated styling component. For example, a Web Control that has only been assigned a **Dimension** Transition Type will only animate changes to the Web Control's size, and not, say, the Web Control's color.

A single Web Control might be associated with multiple animations of different Transition Types.

### Transition Times

Transition Times dictate how fast an animation will appear by defining how long it takes for the transition to fully take place. Three Transition Times come pre-configured for selection:

* **timingQuick** - 100 milliseconds
* **timingMedium** - 500 milliseconds
* **timingSlow** - 1 second

If none of these perfectly suit your needs, you can also define the Transition Time with a custom expression. The expected format is:

```javascript
"{{number}}{{time_units}}"
```

For instance, an animation that takes place over the span of five seconds would be defined by the Transition Time

```javascript
 "5s"
```

An animation that takes place over the span of 70 milliseconds would be defined by the Transition Time:

```javascript
"70ms"
```

## Example: Build a Simple Animation

Let's walk through the process of building a simple animation: a pseudo progress bar that changes width based on user input. When it is finished, it will look like this:

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-3a78b48dab0b3b7d4f2d5c1db6c28b9c134d4601%2Fanimations-v182-0.gif?alt=media)

1. Toggle over to the [Web Flows Builder](../studio/builder-bar/web-flows-builder). Start with a blank Web Page and add the following two Web Controls:

* A [Label](../web-controls/label-web-control) that reads, "What percentage of the bar should be filled?"
* A [Text Input](../web-controls/text-input-web-control) with the placeholder text "90%"

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-9a9587f1ad874a0920626d0e39d34b01fc90c147%2Fanimations-v182-1.png?alt=media)

2. The Text Input Web Control will automatically bind input to the variable `text_input`. To assign this variable a sample value, open the [Variable Tree](../studio/variable-tree) at the bottom left of the Studio and enter "90%" into the right-side column.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-62ead1cd446696f9045c5bb41c6bc7d7ee9f0dae%2Fanimations-v182-2.png?alt=media)

3. Add a [Container](../web-controls/container-web-control) Web Control to the Web Page. Designate this Container "Outer Container."

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-017cc23602afc5f5ac0fccbe754afe271453c2b7%2Fanimations-v182-3.png?alt=media)

4. Inspect the Outer Container. Under **Override Styles > Background**, change the color to **brandPrimaryTint3**.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-bc896020d2199c4009c0e3ca0d00ef0cf4e6a3ff%2Fanimations-v182-4.png?alt=media)

5. Under \*\*Override Styles > Dimensions \*\*, change the height to **fontSizeXLarge**.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-e4e26c872573cf6959fc7acdbf28c01ecefa7a5f%2Fanimations-v182-5.png?alt=media)

6. Nest another Container under Outer Container. Designate this Container "Inner Container."

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-4df88bd24bc01a535df1d5dfafd9abafb7fdee30%2Fanimations-v182-6.png?alt=media)

7. Inspect the Inner Container. Under **Override Styles > Background**, change the color to **brandPrimary**.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-b776e891bb6905e6b0b8e574d2f2dc75a65e3969%2Fanimations-v182-7.png?alt=media)

8. Under **Override Styles > Dimensions**, change the width to the custom expression `text_input`. Note how this will change the appearance of the Inner Container in the Stage so that a portion of the Outer Container is visible:

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-b8208408a88359307d2460eb53293559ca8d5cac%2Fanimations-v182-8.png?alt=media)

Change the height to **fontSizeXLarge**.

9. Under **Animations > Transitions**, select **Dimensions** as the Transition Type and **timingSlow** as the Transition Time.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-13a7880d667933a3ce95181e968771fc70b75567%2Fanimations-v182-9.png?alt=media)

10. Save and Preview your application. Changing the percentage described in the Text Input box will change the percentage of the bar that's filled; note how the transition is animated:

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-3a78b48dab0b3b7d4f2d5c1db6c28b9c134d4601%2Fanimations-v182-10.gif?alt=media)

## Discussion

The pseudo progress bar is a toy example to demonstrate the basic principles of animation, which can be applied to far more complicated use cases. For example, the **Background** and **Dimensions** Transition Types can be applied in tandem with data pulled from a weather API to create an animated thermometer:

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-f635fe3633c98ae1c87d862d7c2d5e1aa079d167%2Fanimations-v182-11.gif?alt=media)

Animations can also be used in combination with gifs, creating even more dynamic UI elements.

![](https://3088276961-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC6qMwMGWBgxnN70QsDuH%2Fuploads%2Fgit-blob-c862350befdb9518b82da70e382ecce010da9bd4%2Fanimations-v182-12.gif?alt=media)
