We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDN: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Typed_OM_API
CSS Typed OM全称CSS Typed Object Model,提供了一系列访问和操作CSS值的方法。
CSS Typed Object Model
在以往,使用HTMLElement.style管理元素的样式,它只是一个string类型,管理很笨拙,可读性也差。而本API将CSS值解析为可读性很高的对象,据此可以科学的管理它。
HTMLElement.style
string
和HTMLElement.style相比,本API更有可读性,性能更高。
有公用类型CSSStyleValue和若干特殊类型如CSSImageValue、CSSKeywordValue等组成。
CSSStyleValue
CSSImageValue
CSSKeywordValue
它是所有CSS值类型的公用类型,提供了parse方法将一个字符串解析成样式对象,例:
parse
// 返回 CSSStyleValue 类型 CSSStyleValue.parse('color', '#f00'); // 返回 CSSTransformValue 类型 CSSStyleValue.parse('transform', 'translate(30px, 20px) rotate(45deg)');
CSS保留关键字类型如initial,例:
initial
// 返回 CSSKeywordValue {value: 'normal'} 类型,因为normal是保留关键字。 $0.computedStyleMap().get('font-style');
提供get、getAll等方法读取样式。
get
getAll
继承于StylePropertyMapReadOnly,提供append、set等方法操作样式,如:
StylePropertyMapReadOnly
append
set
// 将元素的文本颜色设置为红色 $0.attributeStyleMap.set('color', 'red');
HTMLelement.computedStyleMap()返回StylePropertyMapReadOnly类型。
HTMLelement.computedStyleMap()
HTMLElement.attributeStyleMap返回StylePropertyMap类型。
HTMLElement.attributeStyleMap
StylePropertyMap
示例:https://taoliujun.github.io/example/web-api/CSS_Typed_OM_API/index.html
The text was updated successfully, but these errors were encountered:
开发富文本编辑器、代码可视化的场景中,可以使用此API改变元素样式,并在提交时收集样式。在渲染的地方解析这些值并渲染。
Sorry, something went wrong.
No branches or pull requests
CSS Typed OM
CSS Typed OM全称
CSS Typed Object Model
,提供了一系列访问和操作CSS值的方法。在以往,使用
HTMLElement.style
管理元素的样式,它只是一个string
类型,管理很笨拙,可读性也差。而本API将CSS值解析为可读性很高的对象,据此可以科学的管理它。接口
有公用类型
CSSStyleValue
和若干特殊类型如CSSImageValue
、CSSKeywordValue
等组成。CSSStyleValue
它是所有CSS值类型的公用类型,提供了
parse
方法将一个字符串解析成样式对象,例:CSSKeywordValue
CSS保留关键字类型如
initial
,例:其他类型见MDN
StylePropertyMapReadOnly
提供
get
、getAll
等方法读取样式。StylePropertyMap
继承于
StylePropertyMapReadOnly
,提供append
、set
等方法操作样式,如:方法和属性
computedStyleMap
HTMLelement.computedStyleMap()
返回StylePropertyMapReadOnly
类型。attributeStyleMap
HTMLElement.attributeStyleMap
返回StylePropertyMap
类型。示例
示例:https://taoliujun.github.io/example/web-api/CSS_Typed_OM_API/index.html
The text was updated successfully, but these errors were encountered: