CSS Keyframes animation disappearing after complete

Refresh

April 2019

Views

584 time

1

My animation keeps disappearing after it completes its animation. I have followed the answers to other questions but it still doesn't help. My CSS is as follows:

   .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;
        }
    }

I am calling it in my HTML like this:

<div class="upvote-object ani-upvote"></div>

Here's the problem: JSFiddle

UPDATE: Please also know that the animation must also stay on the last frame! (Green)

JLF

1 answers

1

I got it working. But I’m not a CSS expert. So I’m sorry for not being able to explain why it works. Maybe you know why :)

.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
}

UPDATE I got it to work. I think it has to do with the sprite and the position where it stops the animation... if that makes any sense.