如何使用JavaScript将2D或3D转换应用于元素?
使用JavaScript中的transform属性可以将2D或3D转换设置为元素。如果要将值旋转到60度,则将其设置为旋转(60度),依此类推。
示例
您可以尝试运行以下代码,以使用JavaScript对元素进行2D或3D转换-
<!DOCTYPE html>
<html>
<head>
<style>
#box {
margin-left: 20px;
border: 2px solid black;
width: 300px;
height: 250px;
background-color: gray;
color: white;
}
</style>
</head>
<body>
<button onclick = "display()">Apply</button>
<div id = "box"><p>Demo Text</p></div>
<script>
function display() {
document.getElementById("box").style.transform = "rotate(60deg)";
}
</script>
</body>
</html>