我已经为翻牌写了代码。
在这里,卡片翻转旋转(3d旋转)在chrome、firebox、internet explorer中运行得很好,但是当我在safari中打开它时,卡片翻转旋转并不是很好。
在Safari(版本>8.0.0)中,卡是旋转的,但没有3D动画。
如果你们有什么解决办法,请告诉我。
代码如下:
$(".btn").click(function() {
$("#card").toggleClass("flipped");
});
.container {
width: 200px;
height: 260px;
position: relative;
perspective: 800px;
-webkit-perspective: 800px;
-o-perspective: 800px;
-moz-perspective: 800px;
}
#card {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
-webkit-transform-style: preserve-3d;
-webkit-transition: transform 1s;
-o-transform-style: preserve-3d;
-o-transition: transform 1s;
-moz-transform-style: preserve-3d;
-moz-transition: transform 1s;
}
#card figure {
margin: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-o-backface-visibility: hidden;
}
#card .front {
background: red;
font-size: 36px;
}
#card .back {
font-size: 36px;
background: blue;
transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
}
#card.flipped {
transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="container">
<div id="card">
<figure class="front">1</figure>
<figure class="back">2</figure>
</div>
</section>
<button class="btn"><span>Flip card</span>
</button>
最佳答案
您忘记在webkit和其他浏览器中添加前缀
-webkit-transition: -webkit-transform 1s;
$(".btn").click(function() {
$("#card").toggleClass("flipped");
});
.container {
width: 200px;
height: 260px;
position: relative;
perspective: 800px;
-webkit-perspective: 800px;
-o-perspective: 800px;
-moz-perspective: 800px;
}
#card {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 1s;
-webkit-transform-style: preserve-3d;
-webkit-transition: -webkit-transform 1s;
-o-transform-style: preserve-3d;
-o-transition: -o-transform 1s;
-moz-transform-style: preserve-3d;
-moz-transition: -moz-transform 1s;
}
#card figure {
margin: 0;
display: block;
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-o-backface-visibility: hidden;
}
#card .front {
background: red;
font-size: 36px;
}
#card .back {
font-size: 36px;
background: blue;
transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
}
#card.flipped {
transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="container">
<div id="card">
<figure class="front">1</figure>
<figure class="back">2</figure>
</div>
</section>
<button class="btn"><span>Flip card</span>
</button>