Unable to halt animation at the final frame

I'm attempting to implement a character jumping animation that should stop on the last frame, but it's not working as expected. I have tried using

animation-fill-mode: forwards;

but it didn't produce the desired outcome.

Below is the code snippet I am currently using:

.kia-jump {
    width: 320px;
    height: 464px;
    position: absolute;
    top: 1%;
    left: 41%;
    background: url('../images/activity/KiaJumpingAnimation.png') left center;
    animation-fill-mode: forwards;
    animation: jumpAnim 1.67s steps(24) 1;
}

@keyframes jumpAnim {
    100% { background-position: -7920px; }
}

If you would like to view the code in action, here is the JSFiddle link -> https://jsfiddle.net/k4rz5tdy/

Answer №1

There is actually an extra step in your process, causing the background to repeat back to the beginning by default.

.kia-jump {
    width: 320px;
    height: 464px;
    position: absolute;
    top: 1%;
    left: 41%;
    background: url('http://schoolcinema-sconline.rhcloud.com/images/activity/KiaJumpingAnimation.png') left center;
    animation: jumpAnim 1.67s steps(23) 1 forwards;
}

@keyframes jumpAnim {
    100% { background-position: -7590px; }
}

This adjustment was made:

7920 - (7920/24) = 7590

https://jsfiddle.net/RedBreast/k4rz5tdy/2/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing jQuery to overlook the content within my div element?

I have a basic toggle feature for a div connected to a checkbox. $('#step2').hide(); $('#toggle-check').click(function(){ $('#step2').fadeToggle(); }) Why is .hide() not working to hide the contents of #step2? The content ...

Discrepancies in Video Element Size: Mobile Versus Desktop

Why does the video element have different sizing behavior between mobile and desktop? I noticed on this website that on desktop Chrome, its width is about 35% of the browser while on iPad Chrome it's only about 10% Does anyone know why this is happen ...

Choose a Range of DOM Elements

My challenge is to select a range of DOM elements, starting from element until element. This can be done in jQuery like this: (Source) $('#id').nextUntil('#id2').andSelf().add('#id2') I want to achieve the same using JavaScr ...

Dynamically adjust the image link in responsive mode to improve user experience

Is there a way to dynamically change the image links in responsive mode on WordPress? I am displaying thumbnails with a fixed size of 280*200, but I want to switch to medium-sized thumbnails (480*200) when the resolution is between 480px to 600px. Is there ...

Inappropriate functionality of jQuery Code

Take a look at Demo Gallery I'm encountering some bugs that I can't seem to resolve. In Safari, there's a flickering issue when hovering over other elements In Safari and Chrome, the images are not displaying at the correct size (270x128) ...

Automatically resize ui-select dropdown box to the left side

I've been tasked with incorporating AngularJS ui-select into my project, specifically creating a multiselect dropdown. Currently, the dropdown box automatically adjusts its width based on the length of the longest selectable text, causing it to extend ...

What is the method to ensure an element is displayed in Selenium WebDriver?

Looking for assistance on how to choose options from a dropdown when the element is not visible and has a boolean attribute? Here's the HTML code snippet: <select id="visualizationId" style="width: 120px; display: none;" name="visualization"> & ...

various image proportions in HTML

I have an image with a ratio of 16:9 that I want to use on my website. On one of the pages, I display a list of products with images having a ratio of 340x265. When a user clicks on an item in the list, it takes them to the product page where the same im ...

Using CSS alone, incorporate two images within a section in HTML5

Is there a way to add two images inside a section using CSS to make them look like this: However, the only result I can achieve with CSS looks like this: I could use divs in HTML and add the image via HTML, but my class teacher mentioned that it would be ...

Preventing Paste Function in Electron Windows

Currently, I am utilizing Electron and attempting to prevent users from pasting into editable content. While paste and match style remains enabled, the functionality is flawless on Mac devices. However, there seems to be an issue on Windows where regular ...

What is the most efficient way to load a PHP page once the webpage has completely finished loading?

I'm relatively inexperienced when it comes to PHP and JQuery, so please bear with me if my knowledge is limited. Currently, I'm facing an issue where loading a small HTML table that contains information queried from game servers (like shown in t ...

The container that utilizes the grid layout is compact and has a near-invisible height

grid-template: display; font-style: "Josefin Sans", sans-serif; size-of-text: 10px; element-height: 0px; spacing-bottom: 0px; spacing-left: 0px; spacing-right: 0px; spacing-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-up: 0 ...

A guide to replacing or customizing standard components in ReactJS

I need to modify the color property of a common component so I can use it elsewhere. const ViewAllIcon = (props) => ( <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 26 ...

Unable to reset iframe style height in IE8 using JavaScript

I am encountering an issue with resetting the height of an iframe using JavaScript. Here is the code snippet I am working with: var urlpxExt = document.getElementById('urlPx'); urlpxExt.style.height = "200px"; While this approach works well in m ...

Adjusting image width using jQuery

I have been experimenting with creating a Webgl hover effect for an image. The effect works well, but now I am trying to specify a width for the image within jQuery. new hoverEffect({ parent: document.querySelector('.ticket'), intensity1: 0. ...

Styling text on top of an image using CSS

I am attempting to overlay text on top of an image using the following code: .gallery-image { position: relative; } h2 { position: absolute; top: 200px; left: 0; width: 100%; } h2 span { color: white; font: bold 24px/45px Helvetica, Sans-S ...

Ensure that the child div fills the entire parent area when resizing the page

I am facing an issue with a container div that contains two elements. When I resize the window, one inner div moves under the other. However, my requirement is that when one div moves under another on resizing, the first div should occupy the full width o ...

The text in the image caption has been drastically reduced along with the size of the image

Currently, I am dealing with the following code: <div style="min-width: 1000px;"> <p> Some text </p> <div class='div_img_left'> <img src="images/sth.png" alt="missing image" style="max-width ...

Show the time with AM/PM without displaying the year, month, or day

Currently, I am struggling to show the time as AM when my website loads using the format mm-dd-yyyy --:-- AM in a datetime-local input. The value attribute of datetime-local is causing some confusion for me. ...

Automatic keyboard suggestions not working for HTML search input using Ajax

I am currently working on a PHP web application that uses a MySql database. I have implemented a search suggestion box using ajax. The issue I am facing is that the suggestions can be selected with the mouse and auto-completed, but not when using the keybo ...