CSSKeyframeRule: style プロパティ
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年8月.
style は CSSKeyframeRule インターフェイスのプロパティで、 @keyframes ルールの本体で有効な記述子を表す CSSStyleDeclaration オブジェクトです。
値
CSSStyleDeclaration オブジェクトす。
style プロパティ自体は読み取り専用ですが、これはこの CSSStyleDeclaration オブジェクトを置き換えることができないという意味であり、style プロパティに直接代入を行うことは可能です。そうすると、cssText プロパティに代入することと同じことになります。また、CSSStyleDeclaration オブジェクトは setProperty() や removeProperty() メソッドを使用して変更することもできます。
例
この CSS には @keyframes アットルールが記載されています。これは最初の CSSRule であり、 document.styleSheets[0].cssRules で返されます。
myRules[0] は CSSKeyframesRule オブジェクトを返し、その中に各キーフレームに対応する個々の CSSKeyFrameRule オブジェクトが格納されます。
css
@keyframes slide-in {
from {
transform: translateX(0%);
}
to {
transform: translateX(100%);
}
}
js
let myRules = document.styleSheets[0].cssRules;
let keyframes = myRules[0]; // CSSKeyframesRule
console.log(keyframes[0].style); // CSSStyleDeclaration
仕様書
| Specification |
|---|
| CSS Animations Level 1> # dom-csskeyframerule-style> |