Class Fade


public class Fade extends Transition
A transition that animates an element's opacity.

Fade transitions smoothly change the opacity of an element. By default, the element fades to fully transparent (opacity: 0). Use setTo(float) to specify a different target opacity.

Usage:


 // Fade out an element
 panel.addTransition(new Fade());
 panel.transitionForward();

 // Fade to 50% opacity with fast speed
 panel.addTransition(new Fade().setTo(0.5f).setSpeed(8));
 panel.transitionForward();
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Fade

      public Fade()
      Constructs a Fade transition that fades to fully transparent.
  • Method Details

    • setTo

      public Fade setTo(float opacity)
      Sets the target opacity.
      Parameters:
      opacity - the target opacity (0.0 = transparent, 1.0 = opaque)
      Returns:
      this Fade for method chaining
    • getTo

      public float getTo()
      Returns the target opacity.
      Returns:
      the target opacity value
    • getTransitionProperties

      protected String[] getTransitionProperties()
      Returns the CSS property names that this transition animates.

      Subclasses return the CSS properties they modify (e.g., "opacity", "transform", "max-height"). These are used to build the CSS transition shorthand.

      Specified by:
      getTransitionProperties in class Transition
      Returns:
      an array of CSS property names
    • applyEndState

      public void applyEndState(CssStyle style)
      Applies the transition's end state to the given style.

      This method sets the CSS property values that represent the final state of the transition. For example, a fade-out sets opacity: 0.

      Specified by:
      applyEndState in class Transition
      Parameters:
      style - the CssStyle to apply end-state values to
    • snapshotCurrentState

      public void snapshotCurrentState(CssStyle current, CssStyle snapshot)
      Saves the current values of the transition's properties from the element's style.

      Before a transition plays forward, the current property values are saved so they can be restored when playing in reverse. If a property has no current value, the subclass should save a sensible default (e.g., "1" for opacity).

      Specified by:
      snapshotCurrentState in class Transition
      Parameters:
      current - the element's current CssStyle to read values from
      snapshot - the CssStyle to save values into
    • restoreOriginalState

      public void restoreOriginalState(CssStyle style, CssStyle snapshot)
      Restores previously saved property values to the given style.

      This method copies values from the snapshot back to the element's style, causing the browser to animate back to the original state.

      Specified by:
      restoreOriginalState in class Transition
      Parameters:
      style - the CssStyle to restore values to
      snapshot - the CssStyle containing previously saved values