检索CSS需要'getPropertyValue'方法吗? [英] Is the 'getPropertyValue' method required for retrieving CSS?
问题描述
如果我们只能使用 getComputedStyle
,那么你能告诉我为什么我们需要使用 getPropertyValue
方法吗?
Could you tell me why we need to use the getPropertyValue
method if we can use only the getComputedStyle
one?
例如,根据我的理解,这将有效:
For example, this will work, as far as I understand:
var s = getComputedStyle(element, null).opacity;
这相当于以下内容:
var s = getComputedStyle(element, null).getPropertyValue('opacity');
我们可以使用 getComputedStyle
而不用 getPropertyValue
?
Can we use getComputedStyle
without getPropertyValue
?
推荐答案
根据旧的 DOM L2样式, getPropertyValue
不是必需的:
According to the old DOM L2 Style, getPropertyValue
was not required:
CSS2Properties
界面代表
检索和设置CSSStyleDeclaration
。
此界面的属性对应于所有 CSS2中指定的属性
。获取此接口的属性是
相当于调用
的getPropertyValue
方法 CSSStyleDeclaration 界面。设置此
接口的属性相当于调用
的setProperty
方法CSSStyleDeclaration
interface。
The
CSS2Properties
interface represents a convenience mechanism for retrieving and setting properties within aCSSStyleDeclaration
. The attributes of this interface correspond to all the properties specified in CSS2. Getting an attribute of this interface is equivalent to calling thegetPropertyValue
method of the CSSStyleDeclaration interface. Setting an attribute of this interface is equivalent to calling thesetProperty
method of theCSSStyleDeclaration
interface.
但是,实现不需要支持它,所以使用 getPropertyValue
更安全。
However, implementations were not required to support it, so using getPropertyValue
was safer.
实现CSS2Properties
不需要符合CSS模块的实现接口。
A conformant implementation of the CSS module is not required to implement the
CSS2Properties
interface.
但根据较新的 CSSOM ,使用没有 getPropertyValue
的camel-case必须工作:
But according to the newer CSSOM, using camel-case without getPropertyValue
must work:
对于每个CSS属性 property ,它是支持CSS属性,$ b部分接口后面的$ b适用于 camel-cased属性是
,通过运行 属性的-to-idl-attributerel =nofollow> CSS属性到IDL属性算法。
For each CSS property property that is a supported CSS property, the following partial interface applies where camel-cased attribute is obtained by running the CSS property to IDL attribute algorithm for property.
partial interface CSSStyleDeclaration {
attribute DOMString _camel-cased attribute;
};
camel-cased属性
属性,在获取时,必须返回
调用 getPropertyValue()
,参数为运行结果/ cssom /#idl-attribute-to-css-propertyrel =nofollow> IDL属性为CSS属性算法为
驼峰属性。
设置 camel-cased属性
属性必须调用
setProperty()
第一个参数是运行
的结果 IDL属性为
camel-cased属性的CSS属性算法,作为给定值的第二个参数,没有第三个参数。必须重新抛出任何抛出的异常。
Setting the camel-cased attribute
attribute must invoke
setProperty()
with the first argument being the result of
running the IDL attribute to CSS property algorithm for
camel-cased attribute, as second argument the given value, and no third argument. Any exceptions thrown must be re-thrown.
因此, getPropertyValue
为否检索CSS值所需的时间更长。
Therefore, getPropertyValue
is no longer necessary to retrieve CSS values.
这篇关于检索CSS需要'getPropertyValue'方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!