编辑下面的代码:【加编码】
<html> <head> <style> #DIV1 { height: 200px; width: 200px; margin: auto; border: 1px solid black; } #DIV2 { width:150px; height:150px; border: 1px solid black; background-color: coral; transform: rotate(45deg); -ms-transform: rotate(45deg); /* IE 9 */ -webkit-transform: rotate(45deg); /* Opera、Chrome 和 Safari */ } #DIV2original { position:absolute; width:150px; height:150px; border: 1px dashed grey; background-color: lightgrey; opacity:0.5; } </style> </head> <body> <p>点击“尝试一下”按钮,设置选择元素的 x 轴和 y 轴的基点位置都为 0:</p> <p><b>注意:</b>灰色的 DIV 元素表示其中的 DIV2 元素将不会被转换。</p> <button onclick="myFunction()">尝试一下</button> <div id="DIV1">DIV1 <div id="DIV2original">DIV2</div> <div id="DIV2">DIV2</div> </div> <script> function myFunction() { document.getElementById("DIV2").style.transformOrigin = "0 0"; /* Opera、Chrome 和 Safari */ document.getElementById("DIV2").style.WebkitTransformOrigin = "0 0"; /* IE 9 */ document.getElementById("DIV2").style.msTransformOrigin = "0 0"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂