Class KeyFrames


public class KeyFrames extends CssElement
Represents a CSS @keyframes animation rule for defining animation sequences.

KeyFrames allows you to define CSS animations programmatically by specifying keyframe rules at various points in the animation timeline.

Example usage:

 KeyFrames fadeIn = new KeyFrames("fadeIn");
 fadeIn.addRule("from", "opacity: 0");
 fadeIn.addRule("to", "opacity: 1");
 

This generates:

 @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • KeyFrames

      public KeyFrames(String name)
      Constructs a new keyframes animation with the specified name.
      Parameters:
      name - The animation name used to reference this keyframes definition in CSS animations.
  • Method Details

    • addRule

      public KeyFrames addRule(KeyFrameRule rule)
      Adds a keyframe rule to this animation.
      Parameters:
      rule - The KeyFrameRule to add.
      Returns:
      This KeyFrames for method chaining.
    • addRule

      public KeyFrames addRule(String selector, CssStyle style)
      Adds a keyframe rule with a CSS selector and style object.
      Parameters:
      selector - The keyframe selector (e.g., "from", "to", "0%", "50%", "100%").
      style - The CssStyle containing the properties for this keyframe.
      Returns:
      This KeyFrames for method chaining.
    • addRule

      public KeyFrames addRule(String selector, String style)
      Adds a keyframe rule with a CSS selector and style string.
      Parameters:
      selector - The keyframe selector (e.g., "from", "to", "0%", "50%", "100%").
      style - The CSS properties as a string (e.g., "opacity: 0; transform: scale(0.5)").
      Returns:
      This KeyFrames for method chaining.
    • toString

      public String toString()
      Converts this keyframes definition to a CSS string.
      Overrides:
      toString in class Object
      Returns:
      The CSS @keyframes rule as a lowercase string.