【问题标题】:CSS Keyframes animation disappearing after completeCSS关键帧动画完成后消失
【发布时间】:2021-06-30 02:45:52
【问题描述】:

我的动画在完成动画后一直消失。我已经按照其他问题的答案进行了操作,但仍然无济于事。我的 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

更新:还请注意,动画也必须停留在最后一帧! (绿色)

【问题讨论】:

  • 请添加工作的 sn-ps 或 JSFiddle?
  • @RhapX kk 刚刚添加了一个有同样问题的小提琴

标签: html css css-animations keyframe


【解决方案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
    }

更新 我让它工作。我认为这与精灵和它停止动画的位置有关......如果这有任何意义的话。

【讨论】:

  • @JLF 啊,我明白了......我会看看我能做什么
  • 在 Fiddle 上修复了它。不幸的是,这与问题无关,因为我必须将直接远程链接添加到小提琴才能正确链接。它在实际设置中工作。这也是开始图标,应该停留在其他类的最后一帧.ani-upvote
  • 宾果游戏!感谢大家的帮助!
  • @JLF 没问题,搞清楚很有趣 :)
猜你喜欢
  • 2020-08-25
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 2021-11-27
  • 1970-01-01
  • 2020-05-21
  • 1970-01-01
相关资源
最近更新 更多