Transition events
Events that inform you of changes to the state of transition.
읽는 시간 4분최근 업데이트: 한 달 전
Transition events inform you of the changes in a transition's state.
UI Toolkit uses transitions when a 's style property is modified. Changes to property are immediately reflected visually. However, you can use the USS property to interpolate between the initial and end results gradually.
VisualElementVisualElementtransitionThe transition's lifecycle
A transition's lifecycle has the following stages:
-
A's property is modified when you:
VisualElement- Add or remove a class with C# methods. For example: (where
element.ToggleInClassList()is anyelement).VisualElement - Use USS with selectors like .
:hover - Manipulate the element's property. For example:
style(whereelement.style.backgroundColor = Color.red;is anyelement).VisualElement
- Add or remove a class with C# methods. For example:
-
Ais sent.
TransitionRunEvent -
If the resolvedproperty for the changing property has a value other than
transition-delay, nothing happens for the duration of the delay.0 -
After the delay, ais sent, and the transition starts with the property at its initial value.
TransitionStartEvent -
For the length of time set by, the transition occurs. During that time, the property goes from its initial to its final value.
transition-duration -
If the property is changed to a new value during the transition,is sent. The transition process restarts at step 2.
TransitionCancelEvent -
After theelapses, the property sets to its final value. A
transition-durationis sent.TransitionEndEvent
Transition events reference table
The following table describes the transition events and their propagation phases:
Event | Description | Trickles down | Bubbles up | Cancellable |
|---|---|---|---|---|
| TransitionRunEvent | Sent when a transition is created. | Yes | ||
| TransitionStartEvent | Sent when a transition's delay phase ends and the transition starts. | Yes | ||
| TransitionEndEvent | Sent when a transition ends. | Yes | ||
| TransitionCancelEvent | Sent when an a transition is canceled. | Yes |
Behavior
Each transition property has its own lifecycle and its own transition events. You can access the current property with an event's property.
stylePropertyNamesIf a shorthand USS property is changed, every component also gets its own lifecycle. For example, if you change , , , and , they all get their own , and , for a total of 12 separate events.
marginmargin-leftmargin-rightmargin-topmargin-bottomTransitionRunEventTransitionStartEventTransitionEndEventIf you set to , the and are sent one after the other within a few milliseconds.
transition-delay0TransitionRunEventTransitionStartEventIf you set to a value below , the transition won't start at the beginning. For example, with a of seconds and of seconds, the and is sent with an property set to seconds and the transition effectively starts at the third second of a five-second animation.
transition-delay0transition-delay-3transition-duration5TransitionRunEventTransitionStartEventelapsedTime3Event list
This section describes the , , and of each transition event.
targetstylePropertyNameselapsedTimeTransitionRunEvent
A event is sent when a transition is created.
TransitionRunEvent- : The element that executes the transition.
target - : The list of properties modified by the transition.
stylePropertyNames - : The time since the start of the transition.
elapsedTime
TransitionStartEvent
A event is sent when the transition's delay phase ends and the transition begins.
TransitionStartEvent- : The element that executes the transition.
target - : The list of properties modified by the transition.
stylePropertyNames - : The time since the start of the transition.
elapsedTime
TransitionEndEvent
A event is sent when a transition ends.
TransitionEndEvent- : The element that executes the transition.
target - : The list of properties modified by the transition.
stylePropertyNames - : The time since the start of the transition.
elapsedTime
TransitionCancelEvent
A event is sent when a transition is interrupted by the property being changed again.
TransitionCancelEvent- : The element that executes the transition.
target - : The list of properties modified by the transition.
stylePropertyNames - : The time since the start of the transition.
elapsedTime
Examples
- Create a transition event: This example demonstrates the lifecycle of a transition event.
- Create looping transitions: This example demonstrates how to leverage the to create transitions that loop.
TransitionEndEvent - Create a simple transition with UI Builder and C# script: This example demonstrates how to create simple transitions with the UI Builder and C# script.