DWC Transitions
Overview
CSS transitions allow changes to CSS properties to occur gradually over time instead of immediately, creating smoother visual effects in DWC applications. They can be used to improve interactions such as hover effects, color changes, scaling, and other state changes while keeping the behavior controlled through CSS.
Basic Syntax
The CSS transition shorthand defines how a property changes from one state to another. It can specify the property to transition, the duration of the transition, the timing function, and an optional delay.
|
Transition Properties
CSS transitions use individual properties to control what changes, how long the transition takes, how the change progresses over time, and whether it starts after a delay.
The following table summarizes the transition properties used in this section:
| Property | Description | Example |
|---|---|---|
| transition-property | Which CSS property to animate | background-color |
| transition-duration | How long the animation takes | 0.3s, 300ms |
| transition-timing-function | The acceleration curve | ease, linear, ease-in-out |
| transition-delay | Delay before animation starts | 0.1s |
Note: Not every CSS property can be transitioned. Before relying on a transition, verify that the property supports animation in the CSS reference.
Timing Functions
The transition timing function property determines how the speed of a transition changes over its duration. Different timing functions can create constant-speed, gradual, or customized transition effects. For more information, see: transition-timing-function.
The following table summarizes commonly used timing functions:
| Function | Description |
|---|---|
| linear | Constant speed |
| ease | Slow start, fast middle, slow end (default) |
| ease-in | Slow start |
| ease-out | Slow end |
| ease-in-out | Slow start and end |
| cubic-bezier() | Custom curve |
Common Use Cases
CSS transitions can be applied to different interface elements to create smooth visual effects when their properties change. The following examples demonstrate common uses of transitions in DWC applications.
Button Hover Effect
A transition can provide visual feedback when the user moves the pointer over a button. The following example changes the background color and increases the button's scale by 1.05, with both transitions taking 0.2s.
|
Color Theme Transition
Transitions can provide smooth visual changes when switching between DWC color themes. The following example applies a 0.3s transition to the background and text colors when their CSS custom property values change.
|
Expanding Element
A transition can create a gradual expansion or collapse effect by changing an element's max-height. The following example transitions the maximum height of a panel from 0 to 500px when the expanded class is applied.
|
Multiple Transitions
Multiple CSS transitions can be defined in a single transition declaration by separating them with commas. Each property can have its own duration and timing function, as shown in the following example:
|
Alternatively, use all to apply the same transition settings to all eligible CSS properties whose values change:
|
Note: Use all sparingly. Specifying individual properties provides greater control and helps avoid unintended transitions.
Example in BBj
CSS transitions can be applied to BBj controls by injecting CSS into the DWC page. The following example uses BBjAPI::getWebManager to obtain the web manager, BBjWebManager::injectStyle to inject the CSS, and BBjControl::addClass to assign the CSS class to an existing button.
|
When the user hovers over the button, the CSS applies a scaling factor of 1.02 with a transition duration of 0.2s.
Performance Considerations
The performance of CSS transitions depends on the properties being animated. Some properties can be animated efficiently without recalculating the layout, while others require additional browser processing.
Properties That Animate Well
The following properties can typically be animated efficiently using the GPU.
-
transform(translate, rotate, scale) -
opacity
Properties to Avoid Animating
The following properties can trigger layout recalculation, increasing processing overhead and potentially reducing transition performance:
-
width / height -
margin / padding -
top / left / right / bottom
Note: Where possible, use transform: scale() instead of animating width/height, and transform: translate() instead of animating position properties.
For additional guidance, see: How to create high-performance CSS animations.