このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

CSSKeyframesRule: length プロパティ

Baseline 2024
Newly available

Since March 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

>

lengthCSSKeyframesRule インターフェイスの読み取り専用プロパティで、リスト内の CSSKeyframeRule オブジェクトの数を返します。そのため、それぞれのキーフレームルールを CSSKeyframeRule オブジェクト上でインデックスによりアクセスすることができます。

非負の整数です。これは cssRules プロパティの length と同じ値になります。

この CSS には keyframes アットルールが含まれています。これは最初の CSSRuledocument.styleSheets[0].cssRules で返されます。 myRules[0]CSSKeyframesRule オブジェクトを返します。 cssRules プロパティは 2 つのルールを含む CSSRuleList を返します。

css
@keyframes slide-in {
  from {
    transform: translateX(0%);
  }

  to {
    transform: translateX(100%);
  }
}
js
const myRules = document.styleSheets[0].cssRules;
const keyframes = myRules[0]; // CSSKeyframesRule
console.log(keyframes.length); // 2

仕様書

Specification
CSS Animations Level 1>
# dom-csskeyframesrule-length>

ブラウザーの互換性