如何获得纯CSS的CSS属性值 [英] How to get css property value in pure javascript

查看:110
本文介绍了如何获得纯CSS的CSS属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以百分比得到元素的宽度。我使用下面的函数来获取样式,但它以像素为单位给出值。这里的变量样式可以是宽度,高度等任何CSS属性。

I want to get the width of an element in percentage. I am using the following function to get the style but it gives the value in pixels. Here the variable style can be any css property like width, height etc.

this.getStyle = function(style) {
    var elementStyle = window.getComputedStyle(that.element);
    var value = elementName.getPropertyValue(style);
    return value;
}


推荐答案

好像你正在寻找for

Seems that you're looking for

that.element.style.width
that.element.style.height
etc

这篇关于如何获得纯CSS的CSS属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆