1. 3d效果
1.1 translateZ(数值px)
透视: perspective 800-1200px 数值 可以看出 translateZ 的动态
过度: transition all 1s 显示效果 1秒 让效果不那么突兀, 配合hover效果
对自己视聚位移120px transform: translateZ(120px);
图片的大小不会改变.
<style>
body {
perspective: 900px;
}
.box {
width: 400px;
height: 400px;
margin: 200px auto;
background-color: yellowgreen;
transition: all 1s;
}
.box:hover {
transform: translateZ(120px);
}
</style>
<body>
<div class="box"></div>
</body>
1.2 X Y Z 轴
左手原则
不会做图片,下次改进哈.
X轴: 向右旋转 正值 向左旋转 负值 同理右移动正值 左移动负值
Y轴: 向下旋转 正值 向上旋转 负值 同理下移动正值 上移动负值
Z轴: 向自己的视距移动正值(变大) 这个解释比较难 配合透视: perspective 800-1200px 建议取值800px到1200px
.box {
width: 400px;
height: 400px;
background-color: red;
/* 200px 上外边距 auto 水平居中 */
margin: 200px auto;
/* 过度 10秒 */
transition: all 10s;
}
.box img {
width: 100%;
height: 100%;
}
.box:hover{
/* transform: rotateX(1turn); */
/* Y轴正方位旋转1圈 向右旋转 */
transform: rotateY(1turn);
}
<div class="box">
<img src="../img/2.jpg">
</div>
1.3 transform:scale 缩放
scale(1) 取值 1 一倍(就是原本的模样)
scale(0.5) 缩小0.5倍
记得配 溢出隐藏哦! overflow: hidden
.box {
width: 400px;
height: 400px;
margin: 200px auto;
overflow: hidden;
}
.box img {
width: 100%;
height: 100%;
transition: all 5s;
}
.box:hover img{
transform: scale(1.2);
}
<div class="box">
<img src="../img/1.jpg">
</div>
1.4 3D旋转
打开3d效果 在3d盒子的上级配置 transform-style:preserve-3d
详解如图:
<style>
.box {
/* 相对定位 */
p