1、transform基本方法
1.rotate 旋转 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的执行顺序
transform的执行顺序,后写的动画先执行
3、变化原点
transform-origin 变化原点center center。关键字: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>