Posted in HTML / CSS onMay 03, 2016
本文实例为大家分享了CSS3 3D 位移translate效果实例,供大家参考,具体内容如下
效果图:
示例代码:
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;
- transition: background-color 1s;
- -webkit-transition: background-color 1s;
- }
- #block:hover {
- background-color: purple;
- }
- #op {
- text-align: center;
- }
- #op input {
- width: 800px;
- }
- </style>
- <script>
- function translateall() {
- var x = document.getElementById("translateX").value;
- var y = document.getElementById("translateY").value;
- var z = document.getElementById("translateZ").value;
- document.getElementById("block").style.webkitTransform = "translate3d(" + x + "px," + y + "px," + z + "px)";
- document.getElementById("translatex-span").innerText = x;
- document.getElementById("translatey-span").innerText = y;
- document.getElementById("translatez-span").innerText = z;
- }
- </script>
- </head>
- <body>
- <div id="experiment">
- <div id="block">
- </div>
- </div>
- <div id="op">
- <p>translate x: <span id="translatex-span">0</span>px</p>
- <input type="range" min="-360" max="360" id="translateX" value="0" class="range-control" onmousemove="translateall()"/><br/>
- <p>translate y: <span id="translatey-span">0</span>px</p>
- <input type="range" min="-360" max="360" id="translateY" value="0" class="range-control" onmousemove="translateall()"/><br/>
- <p>translate z: <span id="translatez-span">0</span>px</p>
- <input type="range" min="-360" max="360" id="translateZ" value="0" class="range-control" onmousemove="translateall()"/><br/>
- </div>
- </body>
- </html>
以上就是本文的全部内容,希望对大家的学习有所帮助。
CSS3 3D位移translate效果实例介绍
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@