相当于getcomputedstyle()的jquery [英] jquery equivalent for getcomputedstyle()
问题描述
我在 JavaScript插件中找到了getComputedStyle polyfill
if(!calculated){
window.getComputedStyle = function(el){
this.el = el;
this.getPropertyValue = function(prop){
var re = /(\ - ([a-z]){1})/ g;
if(prop ===float){
prop =styleFloat; $ re $ test(prop)){
prop = prop.replace(re,function(){
return arguments [2] .toUpperCase();
b $ b});
}
返回el.currentStyle [道具]? el.currentStyle [prop]:null;
};
返回此;
};
$ b 是否有与getcomputedstyle();相同的jQuery对象? $ b
解决方案您可以使用 .css()
从doc
.css()方法是从
首个匹配元素中获取样式属性的一种便捷方式,特别是根据
浏览器访问大多数属性的不同方式(基于标准的浏览器中的getComputedStyle())
方法与Internet Explorer中的currentStyle和
runtimeStyle属性相比)以及
浏览器对某些属性使用的不同条款。
像
$(el).css('color')
I found this getComputedStyle polyfill in a JavaScript plugin
if (!computed) {
window.getComputedStyle = function(el) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop === "float") {
prop = "styleFloat";
}
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
};
return this;
};
}
Is there any jQuery equivalent for getcomputedstyle();
解决方案 You can use the getter version of .css().
From doc
The .css() method is a convenient way to get a style property from the
first matched element, especially in light of the different ways
browsers access most of those properties (the getComputedStyle()
method in standards-based browsers versus the currentStyle and
runtimeStyle properties in Internet Explorer) and the different terms
browsers use for certain properties.
like
$(el).css('color')
这篇关于相当于getcomputedstyle()的jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!