3D移动是在2D移动的基础上多加了Z轴方向
(注意 : translateZ一般用px单位)
CSS:
body {
/* 透视写在被观察元素的父盒子上 */
perspective: 200px;
}
div {
transition: all 3s;
width: 200px;
height: 200px;
background-color: pink;
/* transform:translateX(100px);
transform:translateY(100px); */
/* transform: translateX(100px) translateY(100px) translateZ(100px); */
/* transform: translate3d(400px, 100px, 100px); */
/* xyz是不能省略的 如果没有需要写0 */
}
div:hover {
transform: translate3d(400px, 100px, 100px);
}
HTML:
<div></div>
在2D平面产生进大远小视觉立体,但是只是效果二维的
(理解成3D物体投影在2D平面内)
(透视写在被观察元素的父盒子上)
3D旋转可以让元素沿着x,y,z轴或者自定义轴进行旋转
语法:
对於元素旋转的方向判断可以使用左手准则
CSS:
<style>
body {
perspective: 300px;
}
div {
width:300px;
height:300px;
background-color: blanchedalmond;
display: block;
margin: 100px auto;
transition: all 2s;
}
div:hover {
/* transform: rotateZ(360deg); */
/* transform: rotate3d(x,y,z,deg); */
transform: rotate3d(1, 1, 1, 360deg);
}
</style>
HTML:
<div>滑鼠放上去将会旋转</div>
CSS:
body {
perspective: 500px;
}
.box {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
transition: all 2s;
/* 让子元素保持3d立体空间 */
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(180deg);
}
.box div {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: pink;
}
.box div:last-child {
background-color: purple;
transform: rotateX(60deg);
}
HTML:
<div class="box">
<div></div>
<div></div>
</div>
<<: D21 - 走!去浏览器吃 好味双响 BOM DOM 饭
今天要介绍的 Tip 是有关於 pipe 的 pure 与 impure,当没有任何额外的设定下,自...
根据官方文件给的方法上传 https://firebase.google.com/docs/stor...
广告中,很多人一昧追求着浮夸的字眼来置入关键字,希望广告可以这样就脱颖而出,但事实上,你真的知道消费...
专案介绍 这个专案会带你使用HTML和CSS,打造专属於你的个人履历网页。 预览图: 首先,我们从H...
文件物件模型 (DOM) 文件物件模型(DOM)是HTML、XML 和 SVG 文件的程序介面。它提...