Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CSSKeyframesRule

CSSKeyframesRule

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨August 2016⁩.

* Some parts of this feature may have varying levels of support.

TheCSSKeyframesRule interface describes an object representing a complete set of keyframes for a CSS animation. It corresponds to the contents of a whole@keyframesat-rule.

CSSRule CSSKeyframesRule

Instance properties

Inherits properties from its ancestorCSSRule.

CSSKeyframesRule.name

Represents the name of the keyframes, used by theanimation-name property.

CSSKeyframesRule.cssRulesRead only

Returns aCSSRuleList of the keyframes in the list.

CSSKeyframesRule.lengthRead only

Returns the number of keyframes in the list.

Instance methods

Inherits methods from its ancestorCSSRule.

CSSKeyframesRule.appendRule()

Inserts a new keyframe rule into the current CSSKeyframesRule. The parameter is a string containing a keyframe in the same format as an entry of a@keyframes at-rule. If it contains more than one keyframe rule, aDOMException with aSYNTAX_ERR is thrown.

CSSKeyframesRule.deleteRule()

Deletes a keyframe rule from the current CSSKeyframesRule. The parameter is the index of the keyframe to be deleted, expressed as a string resolving as a number between0% and100%.

CSSKeyframesRule.findRule()

Returns a keyframe rule corresponding to the given key. The key is a string containing an index of the keyframe to be returned, resolving to a percentage between0% and100%. If no such keyframe exists,findRule returnsnull.

Example

Using CSSKeyframesRule

The CSS includes a keyframes at-rule. This will be the firstCSSRule returned bydocument.styleSheets[0].cssRules.myRules[0] returns aCSSKeyframesRule object.

css
@keyframes slide-in {  from {    transform: translateX(0%);  }  to {    transform: translateX(100%);  }}
js
const myRules = document.styleSheets[0].cssRules;const keyframes = myRules[0]; // a CSSKeyframesRule

Accessing indexes

CSSKeyframesRule can be indexed like an array, and functions similar to itscssRules property.

js
const keyframes = document.styleSheets[0].cssRules[0];for (let i = 0; i < keyframes.length; i++) {  console.log(keyframes[i].keyText);}// Output:// 0%// 100%

Specifications

Specification
CSS Animations Level 1
# interface-csskeyframesrule

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp