【发布时间】:2019-07-12 14:32:28
【问题描述】:
我有一个盒子,盒子里有一张图片。我正在使用 CSS3 object-fit 属性来用图像填充框。我也需要一个移动的动画。我正在使用关键帧动画来移动图像。
这是我的 HTML
<div class="item">
<img src="https://placeimg.com/640/480/any">
</div>
<br>
<button>
animation
</button>
我的 CSS 放在这里,
.item {
width: 200px;
height: 200px;
border: 1px solid #000;
}
.item img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: 0px 0;
}
.item.active img {
-webkit-animation: objectMove 2s;
animation: objectMove 2s;
/* object-position: 100px 0; */
}
@-webkit-keyframes objectMove {
from {
object-position: 0 0;
}
to {
object-position: 100px 0;
}
}
@keyframes objectMove {
from {
object-position: 0 0;
}
to {
object-position: 100px 0;
}
}
这是我的 javascript,
$('button').click(function(){ $('.item').addClass('active');
setTimeout(function(){ $('.item').removeClass('active'); }, 2000); })
它在 chrome、mozilla 和 edge 中运行良好。但不能在 safari 中工作。
Here is the jsfiddle of the same.
谁能帮我解决一下?
【问题讨论】:
标签: css safari cross-browser css-animations keyframe