Safari CSS 叠加动画问题
Safari CSS issue with overlayed animations
我有一个简单的卡片翻转动画,它在我测试过的浏览器上运行良好。
但是,当此卡片翻转动画发生在另一个正在动画处理的 div 之上时,Safari 会出现问题。出于某种原因,在 Safari 上,当卡片翻转时它有点消失在 "background div" 后面。我认为这可能是一个 z-index
问题,但根据我的尝试,它不是。
为使示例简单,背景 div 为灰色。这个想法是在背景中产生发光效果。
下面是我的代码示例,我已经在 Chrome、Firefox 和 Edge 上测试过,它工作正常,但是在 Safari 上,当卡片翻转时它会消失。
$(document).ready(function() {
$('button').click(function() {
$('.wrapper').toggleClass('flip');
});
});
.perspective {
perspective: 1000px;
margin: 50px;
position: relative;
width: 175px;
height: 250px;
}
.some-bg {
background-color: #ccc;
background-position: center;
width: 100%;
height: 100%;
position: absolute;
animation: test-bg-animation 1s infinite linear;
}
@keyframes test-bg-animation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.wrapper {
width: 125px;
height: 175px;
border: 1px solid blue;
position: absolute;
transform-style: preserve-3d;
transition: all 250ms;
top: 35px;
left: 25px;
}
.wrapper.flip {
transform: rotateY(180deg);
}
.card-face {
width: 100%;
height: 100%;
position: absolute;
-webkit-backface-visibility: hidden;
}
.back {
background-color: tomato;
}
.front {
background-color: #bada55;
transform: rotateY(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="perspective">
<div class="some-bg"></div>
<div class="wrapper">
<div class="card-face front">Front</div>
<div class="card-face back">Back</div>
</div>
</div>
<button>Flip Me!</button>
您可以通过将 .some-bg
和 .wrapper
div 嵌套到具有相对定位父级的绝对定位 div 中来解决此问题。
查看此 fiddle 示例:
https://jsfiddle.net/voLzv68w/
我有一个简单的卡片翻转动画,它在我测试过的浏览器上运行良好。
但是,当此卡片翻转动画发生在另一个正在动画处理的 div 之上时,Safari 会出现问题。出于某种原因,在 Safari 上,当卡片翻转时它有点消失在 "background div" 后面。我认为这可能是一个 z-index
问题,但根据我的尝试,它不是。
为使示例简单,背景 div 为灰色。这个想法是在背景中产生发光效果。
下面是我的代码示例,我已经在 Chrome、Firefox 和 Edge 上测试过,它工作正常,但是在 Safari 上,当卡片翻转时它会消失。
$(document).ready(function() {
$('button').click(function() {
$('.wrapper').toggleClass('flip');
});
});
.perspective {
perspective: 1000px;
margin: 50px;
position: relative;
width: 175px;
height: 250px;
}
.some-bg {
background-color: #ccc;
background-position: center;
width: 100%;
height: 100%;
position: absolute;
animation: test-bg-animation 1s infinite linear;
}
@keyframes test-bg-animation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.wrapper {
width: 125px;
height: 175px;
border: 1px solid blue;
position: absolute;
transform-style: preserve-3d;
transition: all 250ms;
top: 35px;
left: 25px;
}
.wrapper.flip {
transform: rotateY(180deg);
}
.card-face {
width: 100%;
height: 100%;
position: absolute;
-webkit-backface-visibility: hidden;
}
.back {
background-color: tomato;
}
.front {
background-color: #bada55;
transform: rotateY(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="perspective">
<div class="some-bg"></div>
<div class="wrapper">
<div class="card-face front">Front</div>
<div class="card-face back">Back</div>
</div>
</div>
<button>Flip Me!</button>
您可以通过将 .some-bg
和 .wrapper
div 嵌套到具有相对定位父级的绝对定位 div 中来解决此问题。
查看此 fiddle 示例: https://jsfiddle.net/voLzv68w/