javascript - jquery 相当于 getcompulatedstyle()

标签 javascript jquery function

我在 JavaScript plugin 中找到了这个 getCompulatedStyle polyfill

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;
  };
}

是否有与 getcompulatedstyle() 等效的 jQuery;

最佳答案

您可以使用 .css() 的 getter 版本.

来自文档

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.

喜欢

$(el).css('color')

关于javascript - jquery 相当于 getcompulatedstyle(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19137507/

相关文章:

javascript - 如何强制图像显示给定的高度和宽度而不在 HTML DIV 标签中拉伸(stretch)?

jQuery Mobile 更改页面未加载 DOM 中已有的页面

javascript - jQuery 之后的文本格式问题

JQuery - 通过合并函数来简化脚本?

javascript - 如何在 Javascript 中向 .submit() 添加回调函数?

javascript - 如何最终在 google map api 中更改标记位置?

javascript - 什么是 domContentLoaded 和 domInteractive 事件?

javascript - 错误 : [ng:areq] Argument 'TasksCtrl' is not a function, 未定义

jquery - $().html 附加到影子 DOM 而不是替换

javascript - 如何迭代对象数组并添加属性