CSS3 3D位移translate的操作方法
来源:爱站网时间:2022-01-12编辑:网友分享
这篇文章主要为大家详细介绍CSS3 3D位移translate的操作方法,感兴趣的小伙伴可以自行前来阅读。下面的时间就交给爱站技术频道小编带大家详细了解下吧!
示例代码:
XML/HTML Code复制内容到剪贴板
- nbsp;html>
- html lang="en">
- head>
- meta charset="UTF-8">
- title>3D位移的Demotitle>
- 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">0span>pxp>
- input type="range" min="-360" max="360" id="translateX" value="0" class="range-control" onmousemove="translateall()"/>br/>
- p>translate y: span id="translatey-span">0span>pxp>
- input type="range" min="-360" max="360" id="translateY" value="0" class="range-control" onmousemove="translateall()"/>br/>
- p>translate z: span id="translatez-span">0span>pxp>
- input type="range" min="-360" max="360" id="translateZ" value="0" class="range-control" onmousemove="translateall()"/>br/>
- div>
- body>
- html>
以上CSS3 3D位移translate的操作方法就是本文的全部内容,希望对大家的学习有所帮助。关注爱站技术频道网站,带你解锁不一样的技术文章。