时间:2021-07-01 10:21:17 帮助过:82人阅读
效果:
代码:
html:
<p class="main"> <p class="box b1"></p> <p class="box b2"></p> </p>
css:
.main { position: absolute; top: 50%; left: 50%; width: 300px; height: 300px; transform: translate(-50%,-50%); -webkit-perspective: 1500; -moz-perspective: 1500; } .box { position: absolute; top: 0; left: 0; width: 300px; height: 300px; transition: all 1s; backface-visibility: hidden; border-radius: 10px; cursor: pointer; } .b1{ background:skyblue; } .b2 { background:tomato; transform: rotateY(-180deg); }
javascript:
var b1 = document.querySelector(".b1"); var b2 = document.querySelector(".b2"); b1.onclick = function() { b1.style.transform = "rotateY(180deg)"; b2.style.transform = "rotateY(0deg)"; } b2.onclick = function() { b2.style.transform = "rotateY(-180deg)"; b1.style.transform = "rotateY(0deg)"; }
-webkit-perspective:透视效果
backface-visibility:隐藏被旋转的 p 元素的背面
相关推荐:
CSS33D翻转相册
基于css3的文字3D翻转特效_html/css_WEB-ITnose
CSS3-3D翻转_html/css_WEB-ITnose
以上就是CSS如何实现卡片3D翻转效果的详细内容,更多请关注Gxl网其它相关文章!