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.

.element {
    transition: property duration timing-function 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.

Button Hover Effect
.button {
    background-color: var(--dwc-color-primary);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.button:hover {
    background-color: var(--dwc-color-primary-dark);
    transform: scale(1.05);
}

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.

.window {
    background-color: var(--dwc-background);
    color: var(--dwc-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

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.

.panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.panel.expanded {
    max-height: 500px;
}

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:

.element {
    transition:
        background-color 0.3s ease,
        transform 0.2s ease-in-out,
        opacity 0.3s ease;
}

Alternatively, use all to apply the same transition settings to all eligible CSS properties whose values change:

.element {
    transition: all 0.3s ease;
}

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.

rem Add transition to a button
css$ = ".my-button {"
css$ = css$ + "  transition: background-color 0.3s ease, transform 0.2s ease;"
css$ = css$ + "}"
css$ = css$ + ".my-button:hover {"
css$ = css$ + "  transform: scale(1.02);"
css$ = css$ + "}"

web! = BBjAPI().getWebManager()
web!.injectStyle(css$)

btn!.addClass("my-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.

See Also

DWC FAQ

BBjButton

BBjWebManager / BBjBuiManager

Dynamic Web Client (DWC) Overview

BBj Theme Engine