Class Move


public class Move extends Transition
A transition that animates an element's position, scale, and rotation via the CSS transform property.

Move builds a composite transform value from its configured parts: translate(x, y), scale(s), and rotate(r). Only non-null parts are included in the output. This allows precise control over each transform function without writing raw CSS strings.

Usage:


 // Slide 200px to the right
 element.addTransition(new Move().setX(200));
 element.transitionForward();

 // Move diagonally and scale up
 new Move().setX("300px").setY("150px").setScale(1.5f)

 // Rotate 45 degrees
 new Move().setRotation(45)

 // Use in a TransitionSequence
 TransitionSequence seq = new TransitionSequence(element);
 seq.add(new Move().setX(200).setDuration(0.5f));
 seq.add(new Move().setX(200).setY(100).setScale(1.4f).setDuration(0.4f));
 seq.play();
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Move

      public Move()
      Constructs a Move transition with no transform values set.

      At least one transform function must be configured via setters before use.

  • Method Details

    • setX

      public Move setX(String value)
      Sets the horizontal translation as a CSS value string.
      Parameters:
      value - any valid CSS length value (e.g., "200px", "50%", "10em")
      Returns:
      this Move for method chaining
    • setX

      public Move setX(int pixels)
      Sets the horizontal translation in pixels.
      Parameters:
      pixels - the translation distance in pixels
      Returns:
      this Move for method chaining
    • setX

      public Move setX(Units units)
      Sets the horizontal translation using a CSS unit value.
      Parameters:
      units - the translation distance as a CSS unit (e.g., new Px(200), new Percent(50))
      Returns:
      this Move for method chaining
    • getX

      public String getX()
      Returns the horizontal translation value.
      Returns:
      the CSS translation value, or null if not set
    • setY

      public Move setY(String value)
      Sets the vertical translation as a CSS value string.
      Parameters:
      value - any valid CSS length value (e.g., "150px", "25%", "5em")
      Returns:
      this Move for method chaining
    • setY

      public Move setY(int pixels)
      Sets the vertical translation in pixels.
      Parameters:
      pixels - the translation distance in pixels
      Returns:
      this Move for method chaining
    • setY

      public Move setY(Units units)
      Sets the vertical translation using a CSS unit value.
      Parameters:
      units - the translation distance as a CSS unit (e.g., new Px(150), new Rem(3))
      Returns:
      this Move for method chaining
    • getY

      public String getY()
      Returns the vertical translation value.
      Returns:
      the CSS translation value, or null if not set
    • setScale

      public Move setScale(float scale)
      Sets the scale factor.

      A value of 1.0 is the original size, 1.5 is 150%, 0.5 is 50%, etc.

      Parameters:
      scale - the scale factor
      Returns:
      this Move for method chaining
    • getScale

      public Float getScale()
      Returns the scale factor.
      Returns:
      the scale factor, or null if not set
    • setRotation

      public Move setRotation(String value)
      Sets the rotation as a CSS angle string.
      Parameters:
      value - any valid CSS angle value (e.g., "45deg", "0.5turn", "1.57rad")
      Returns:
      this Move for method chaining
    • setRotation

      public Move setRotation(int degrees)
      Sets the rotation in degrees.
      Parameters:
      degrees - the rotation angle in degrees
      Returns:
      this Move for method chaining
    • getRotation

      public String getRotation()
      Returns the rotation value.
      Returns:
      the CSS angle value, or null if not set
    • 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