CSS 参考手册
CSS3 transform-origin 属性
Tip:Safari/Chrome用户:为了更好地理解3D 转换属性,请查看 - 演示.
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <style> #div1 { position: relative; height: 200px; width: 200px; margin: 50px; padding: 10px; border: 1px solid black; } #div2 { padding: 50px; position: absolute; border: 1px solid black; background-color: red; transform: rotateY(70deg); transform-origin: 50% 50% 100px; -webkit-transform: rotateY(70deg); /* Safari and Chrome */ -webkit-transform-origin: 50% 50% 100px; /* Safari and Chrome */ } </style> <script> function changeRot(value) { document.getElementById('div2').style.transform = "rotateY(" + value + "deg)"; document.getElementById('div2').style.webkitTransform = "rotateY(" + value + "deg)"; document.getElementById('div2').style.MozTransform = "rotateY(" + value + "deg)"; document.getElementById('div2').style.OTransform = "rotateY(" + value + "deg)"; document.getElementById('persp').innerHTML = value + "deg"; } function changeOrg() { var x = document.getElementById('ox').value; var y = document.getElementById('oy').value; var z = document.getElementById('oz').value; document.getElementById('div2').style.transformOrigin = x + '% ' + y + '% ' + z + 'px'; document.getElementById('div2').style.webkitTransformOrigin = x + '% ' + y + '% ' + z + 'px'; document.getElementById('div2').style.MozTransformOrigin = x + '% ' + y + '% ' + z + 'px'; document.getElementById('div2').style.OTransformOrigin = x + '% ' + y + '% ' + z + 'px'; document.getElementById('origin').innerHTML = x + "% " + y + "% " + z + "px"; } </script> </head> <body> <p><b>Note:</b> Internet Explorer 9 and earlier do not support 3D-transforms.</p> <p>Rotate the red div element, try changing its X-, Y-, and Z-axis:</p> <div id="div1"> <div id="div2">HELLO</div> </div> Rotate:<br> <input type="range" min="-360" max="360" value="70" onchange="changeRot(this.value)" /><br> -webkit-transform: rotateY:(<span id="persp">70deg</span>); <br> X-axis: <input type="range" min="-100" max="200" value="50" onchange="changeOrg()" id="ox" /><br> Y-axis: <input type="range" min="-100" max="200" value="50" onchange="changeOrg()" id="oy" /><br> Z-axis: <input type="range" min="-100" max="200" value="100" onchange="changeOrg()" id="oz" /><br> -webkit-transform-origin: <span id="origin">50% 50% 100px</span>; </body> </html>
运行结果:
点击运行 »