在JavaScript中访问-webkit- vendor前缀 [英] Access the -webkit- vendor prefix in JavaScript
问题描述
如果我正在写一个JavaScript行来设置元素的样式属性,它可能看起来像这样(例如:width):
If I were writing a JavaScript line to set a style attribute of an element it could look like this (this example: "width"):
document.getElementById('myDiv').style.width="50px";
如果CSS元素中有一个破折号,它看起来像这样-top):
and if there is a dash in the CSS element it would look like this (this example: "margin-top"):
document.getElementById('myDiv').style.marginTop="15px";
但是如何访问前缀 -webkit -
,如果我想给它一个像这样的样式:
But how do I access the prefix -webkit-
, if I want to give it a style like this example:
{-webkit-transition: width 1s;}
推荐答案
您有两个选项:
-
style [webkit-transition]
-
style.WebkitTransition
style["-webkit-transition"]
style.WebkitTransition
第一个直接工作。第二个符号称为camel case, foo-bar-baz
变为 fooBarBaz
。因此,当非骆驼案例字符串以 -
开头时,第一个字母在驼峰情况下大写。
The first directly works. The second notation is called camel case, and foo-bar-baz
becomes fooBarBaz
. As a result, when a non camel case string starts with -
, the first letter is capitalized in camel case.
这篇关于在JavaScript中访问-webkit- vendor前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!