Class Bounce

java.lang.Object
com.oorian.css.animations.Animation
com.oorian.css.animations.Bounce

public class Bounce extends Animation
A looping animation that bounces an element up and down with a squash-and-stretch effect.

The element compresses, launches upward, and settles back with secondary bounces, creating a natural, physics-inspired motion. The bounce height can be customized with setHeight(String).

Usage:


 // Default bounce animation
 icon.animate(new Bounce());

 // Bounce with greater height
 icon.animate(new Bounce().setHeight("-1em"));
 
Since:
2026
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Bounce

      public Bounce()
      Constructs a Bounce animation with default height and speed 1 (1000ms).
  • Method Details

    • setHeight

      public Bounce setHeight(String height)
      Sets the bounce height.

      The value should be negative for upward bouncing (e.g., "-0.5em", "-20px"). Use CSS length units.

      Parameters:
      height - the bounce height as a CSS value (e.g., "-0.5em")
      Returns:
      this Bounce for method chaining
    • getHeight

      public String getHeight()
      Returns the bounce height.
      Returns:
      the bounce height CSS value
    • getKeyFramesId

      public String getKeyFramesId()
      Returns the unique ID for this animation's keyframes style element.

      This ID is used to deduplicate keyframe injection into the page head. Subclasses with configurable keyframes (e.g., Beat with a custom scale) should return a unique ID per configuration to avoid collisions.

      Specified by:
      getKeyFramesId in class Animation
      Returns:
      the keyframes style element ID
    • createKeyFrames

      public KeyFrames createKeyFrames()
      Creates the @keyframes definition for this animation.
      Specified by:
      createKeyFrames in class Animation
      Returns:
      a KeyFrames object defining the animation sequence
    • getDefaultTimingFunction

      protected AnimationTimingFunction getDefaultTimingFunction()
      Returns the default timing function for this animation.

      Each animation subclass provides its own default timing function. For custom cubic-bezier or steps timing, override Animation.getTimingFunctionValue() instead.

      Specified by:
      getDefaultTimingFunction in class Animation
      Returns:
      the default timing function, or null if Animation.getTimingFunctionValue() provides a custom value
    • getTimingFunctionValue

      protected String getTimingFunctionValue()
      Returns the CSS timing function value as a string.

      By default, delegates to Animation.getDefaultTimingFunction(). Override this method to provide custom timing function values like cubic-bezier(...) or steps(...) that are not represented by the enum.

      Overrides:
      getTimingFunctionValue in class Animation
      Returns:
      the CSS timing function value