我的动画在完成动画后不断消失。我已经按照其他问题的答案,但它仍然没有帮助。我的CSS如下:
.upvote-object {
width: 50px;
height: 62.5px;
background: url('/icons/upvote.png') left center no-repeat;
background-size: 50px 62.5px;
&.upvoted {
background: url('/icons/upvoted.png') left center no-repeat;
background-size: 50px 62.5px !important;
}
}
.ani-upvote {
background: url('/icons/upvote-sprite.png') left center no-repeat;
background-size: 1700px 62.5px;
animation: play 3s steps(34);
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
opacity: 1;
}
@keyframes play {
100% {
background-position: -1700px;
opacity: 1;
}
}
@-webkit-keyframes play {
100% {
background-position: -1700px;
opacity: 1;
}
}
我在我的HTML中调用它:
<div class="upvote-object ani-upvote"></div>
问题在于:JSFiddle
更新:也请知道动画也必须留在最后一帧! (绿色)
答案 0 :(得分:1)
我得到了它的工作。但我不是CSS专家。所以我很抱歉无法解释它的工作原理。也许你知道为什么:)
.upvote-object {
width: 50px;
height: 62.5px;
background: url('http://sstaging-parts.herokuapp.com/icons/upvote.png') left center no-repeat;
background-size: 50px 62.5px;
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
opacity: 1;
}
.ani-upvote {
background: url('http://staging-parts.herokuapp.com/icons/upvote-sprite.png') left center no-repeat;
background-size: 1700px 62.5px;
animation: play 2s steps(33); // changed the steps to 33
animation-fill-mode: forwards;
-webkit-animation-fill-mode: forwards;
opacity: 1;
}
@keyframes play {
100% { background-position: -1650px; opacity: 1; }
}
@-webkit-keyframes play {
100% { background-position: -1650px; opacity: 1; } // Changed the position to -1650
}
<强>更新强> 我得到了它的工作。我认为它与精灵及其停止动画的位置有关......如果这有意义的话。