Accessing vendor-specific CSS properties w/JavaScr

2020-04-09 14:17发布

I am curious how one would access/modify properties like -moz-transition (or any property from this list) by means of native javascript i.e. without relying on jQuery's .css('property', 'value');

For instance, to change an element's background-color one would work with element.style.backgroundColor.

Do vendor-specific property names just get camelCased and become operable? I couldn't do so, maybe they are no longer represented by properties of style and should be modified elsewhere? Or maybe they are not accessible through DOM at all?

2条回答
疯言疯语
2楼-- · 2020-04-09 14:55

Use upper camel case, e.g., el.style.MozTransition.

Example: http://jsfiddle.net/R3y6f/1/

查看更多
SAY GOODBYE
3楼-- · 2020-04-09 15:09

ex: -webkit-box-shadow

.style.setProperty("-webkit-box-shadow", "0 0 7px #ccc", null);
.style.removeProperty("-webkit-box-shadow");
.style["-webkit-box-shadow"];
查看更多
登录 后发表回答