CSS3 3D旋转rotate效果实例介绍
程序员文章站
2023-12-11 19:47:40
这篇文章主要为大家详细介绍了CSS3 3D旋转rotate效果实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下... 16-05-03...
本文实例为大家分享了css3 3d旋转rotate效果实例,供大家参考,具体内容如下
效果图:
示例代码
xml/html code复制内容到剪贴板
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>3d旋转的demo</title>
- <style>
- #experiment {
- -webkit-perspective: 800;
- -webkit-perspective-origin: 50% 50%;
- -webkit-transform-style: -webkit-preserve-3d;
- }
- #block {
- width: 200px;
- height: 200px;
- background-color: pink;
- margin: 100px auto;
- -webkit-transition: background-color 3s;
- }
- #block:hover {
- background-color: purple;
- }
- #ep {
- text-align: center;
- }
- #ep input {
- width: 800px;
- }
- </style>
- <script>
- function rotate() {
- var x = document.getelementbyid("rotatex").value;
- var y = document.getelementbyid("rotatey").value;
- var z = document.getelementbyid("rotatez").value;
- document.getelementbyid("block").style.webkittransform = "rotatex(" + x + "deg) rotatey(" + y + "deg) rotatez(" + z + "deg)";
- document.getelementbyid("degx-span").innertext = x;
- document.getelementbyid("degy-span").innertext = y;
- document.getelementbyid("degz-span").innertext = z;
- }
- </script>
- </head>
- <body>
- <div id="experiment">
- <div id="block"></div>
- </div>
- <div id="ep">
- <p>rotate x: <span id="degx-span">0</span>deg</p>
- <input type="range" min="-360" max="360" id="rotatex" value="0" class="range-control" onmousemove="rotate()"/><br/>
- <p>rotate y: <span id="degy-span">0</span>deg</p>
- <input type="range" min="-360" max="360" id="rotatey" value="0" class="range-control" onmousemove="rotate()"/><br/>
- <p>rotate z: <span id="degz-span">0</span>deg</p>
- <input type="range" min="-360" max="360" id="rotatez" value="0" class="range-control" onmousemove="rotate()"/><br/>
- </div>
- </body>
- </html>
以上就是本文的全部内容,希望对大家的学习有所帮助。