<分区>
如何从元素中获取自定义 CSS 变量的内联样式?
我可以轻松获取宽度或任何其他传统样式,但在尝试获取自定义内联样式时出现错误。有没有办法提取这种样式数据?预先感谢您提供的任何帮助。请不要使用 jQuery。
var styleDivWidth = document.getElementById('myId').style.width;
console.log(styleDivWidth);
/*
var styleDivRotation = document.getElementById('myId').style.--rotation;
console.log(styleDivRotation);
*/
.myClass{
background-color:red;
float:left;
--rotation: 45deg;
transform: rotate(var(--rotation));
margin:20px;
}
<div id="myId" class="myClass" style="width:100px; height:100px;
--rotation:-45deg;">