1、transform基本方法
1.rotate 旋轉(zhuǎn) deg
rotateX/rotateY/rotateZ
2.translate 平移 px 正值向前移動,負值向后移動
translateX/translateY/translateZ
3.skew 斜切 deg
skewX/skew
正值是拉左上角和右下角厦凤,負值拉右上角和左下角
4.scale 縮放(原始大小的多少倍)
scaleX/scaleY
5.perspective 景深
perspective 屬性定義 3D 元素距視圖的距離梦鉴,以像素計。
rotate,skew,scale都是圍繞著元素的中心點進行變化
2筋讨、transform的執(zhí)行順序
transform的執(zhí)行順序赛糟,后寫的動畫先執(zhí)行
3派任、變化原點
transform-origin 變化原點center center。關(guān)鍵字:bottom璧南、top掌逛、center、left司倚,right豆混,長度單位(px、em动知、rem)皿伺,會受到影響的屬性有rotate、skew盒粮、scale
4鸵鸥、3D盒子
制作3D盒子代碼:
<div id="wrap">
<div id="box">
<span>前</span>
<span>右</span>
<span>后</span>
<span>左</span>
<span>上</span>
<span>下</span>
<div>
</div>
<style>
#wrap {
width: 100px;
height: 100px;
border: 1px solid #000;
padding: 100px;
-webkit-perspective: 300px;
perspective: 300px;
}
#box{
width: 100px;
height: 100px;
color: #fff;
font-size: 50px;
line-height: 100px;
text-align: center;
position: relative;
-webkit-transform-style:preserve-3d;
transform-style:preserve-3d;
-webkit-transform: translateZ(-50px) rotateY(0deg);
transform: translateZ(-50px) rotateY(0deg);
transition:5s;
}
#box span{
position: absolute;
left: 0;
top: 0;
width: 100px;
height: 100px;
transition: 5s;
}
#box span:nth-of-type(1){
background:red;
-webkit-transform:rotate(0deg) translateZ(50px);
transform:rotate(0deg) translateZ(50px);
}
#box span:nth-of-type(2){
background: yellow;
-webkit-transform: rotateY(90deg) translateZ(50px);
transform: rotateY(90deg) translateZ(50px);
}
#box span:nth-of-type(3){
background: blue;
-webkit-transform: rotateY(180deg) translateZ(50px);
transform: rotateY(180deg) translateZ(50px);
}
#box span:nth-of-type(4){
background: green;
-webkit-transform: rotateY(270deg) translateZ(50px);
transform: rotateY(270deg) translateZ(50px);
}
#box span:nth-of-type(5){
background: pink;
-webkit-transform: rotateX(90deg) translateZ(50px);
transform: rotateX(90deg) translateZ(50px);
}
#box span:nth-of-type(6){
background: #000;
-webkit-transform: rotateX(-90deg) translateZ(50px);
transform: rotateX(-90deg) translateZ(50px);
}
</style>
<script>
window.onload=function(){
var box=document.querySelector('#box');
box.style.WebkitTransform=box.style.transform='translateZ(-50px) rotateY(360deg)';
}
</script>