此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

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月⁩.

CSSKeyframeRule 的只读属性 CSSKeyframeRule.style 表示 CSSStyleDeclaration 接口。

CSSStyleDeclaration 对象,具有以下属性:

计算标志

未设置。

声明

规则中的声明,按指定顺序排列,简写属性已展开为长格式。

父 CSS 规则

上下文对象,是 this 的别名。

所属节点

空值。

示例

以下 CSS 包含一个 @keyframes 规则。这将是 document.styleSheets[0].cssRules 返回的第一个 CSSRulemyRules[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

浏览器兼容性