CSS 关键帧动画完成后消失
CSS Keyframes animation disappearing after complete
我的动画在完成动画后一直消失。我已经按照其他问题的答案进行操作,但仍然无济于事。我的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
更新: 还请注意动画也必须停留在最后一帧! (绿色)
我成功了。但我不是 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
}
更新
我让它工作了。我认为这与精灵和它停止动画的位置有关......如果这有意义的话。
我的动画在完成动画后一直消失。我已经按照其他问题的答案进行操作,但仍然无济于事。我的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
更新: 还请注意动画也必须停留在最后一帧! (绿色)
我成功了。但我不是 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
}
更新 我让它工作了。我认为这与精灵和它停止动画的位置有关......如果这有意义的话。