标签正反面切换
2019-11-06 本文已影响0人
guoss
1.使用transform-style:preserve-3d(IE浏览器中不适配)
<div class="wrap">
<div class="front"></div>
<div class="back"></div>
</div>
.wrap {
position: relative;
width: 100px;
height: 100px;
transform-style: preserve-3d;
transition: 1s;
}
.wrap:hover {
transform: rotateY(180deg);
}
.front {
position: absolute;
width: 100%;
height: 100%;
background: red;
transform: rotateY(0);
}
.back {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background: pink;
transform: rotateY(180deg);
z-index: 1;
}
2.直接使用transform的过渡动画,能够兼容IE各个版本浏览器
.wrap {
position: relative;
width: 100px;
height: 100px;
}
.front {
width: 100%;
height: 100%;
z-index: 2;
background: red;
transition: 1s;
}
.back {
top: 0;
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
background: pink;
transition: 1s;
}
.wrap:hover .front {
opacity: 0;
}
.wrap:hover .back {
opacity: 1;
}
.wrap:hover .front, .wrap:hover .back{
transform: rotateY(360deg);
}
上述的transform兼容各个浏览器的话需要加上对应的前缀