Avoid making the check mark disappear in an SVG animation

After perfecting my CSS animation, I have the circle looping around to complete its shape while a check mark fills in the middle with a slight delay. Once both shapes are completed simultaneously, the check mark disappears.

The reason for the disappearing check mark at the end is due to setting the opacity to 0 in the CSS for the check mark element. While exploring other techniques, I noticed this method is commonly used to make an element appear after an animation completes.

I am puzzled as to why, even though the opacity is set to 1 at the end of the animation, the check mark is still vanishing. Is there a solution to this issue or perhaps a better approach to achieve my desired outcome?

Any assistance on this matter would be highly appreciated!

Below is the SVG code snippet:

<svg xmlns="http://www.w3.org/2000/svg" id="checkmark-group" viewBox="0 0 128 128">
  <title>
    Successful Login
  </title>
  <circle id="circle" cx="64" cy="64" r="59.4"/>
  <path id="checkmark" d="M24.75 62l27.5 27.5 51-51"/>
</svg>

Here is the corresponding CSS style section:

svg {
  width: 128px;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
}

circle, #checkmark {
  fill: none;
  stroke: #000;
  stroke-linecap: round;
  stroke-miterlimit: 10;
  stroke-width: 4px;
  stroke-dasharray: 400;
}

#checkmark {
  animation: checkmark-stroke 3s reverse;
  animation-delay: 1s;
  opacity: 0;
}

@keyframes checkmark-stroke {
  0% {
    stroke-dashoffset: 0;
    opacity: 0;
  }
  1% { opacity: 1; }
  100% {
    stroke-dashoffset: 400;
    opacity: 1;
  }
}

circle {
  animation: circle-stroke 3s;
}

@keyframes circle-stroke {
  from {
    stroke-dashoffset: -400;
  }
  to {
    stroke-dashoffset: 0;
  }
}

You can view the animated code on CodePen: https://codepen.io/abrielshipley/pen/QOKBGE

Answer №1

If you're searching for the solution, look no further than the animation-fill-mode property. To make it work, simply append the term forwards to both instances of the animation shorthand properties.

It appears that using both reverse and forwards simultaneously might not be compatible (at least in a way that's easily understandable). To address this issue, try adjusting the keyframes for the checkmark-stroke animation by swapping the positions of 0% and 100%. You may also need to modify the animation-timing-function: https://codepen.io/anon/pen/rYWvyq

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

If the iframe's CSS source is updated, the parent's CSS source will also change

I'm currently working on a unique school project that involves creating multiple CSS styles for different views. <link rel="stylesheet" type="text/css" href="css/main.css" title="main" media="screen"> <link rel="stylesheet" type="text/css" h ...

Display only distinct dates in the ng-repeat list

I'm trying to display an unordered list created using ng-repeat. Each list item includes a month header and a blog post. I'm struggling to find a clean solution to only show one instance of each month name without resorting to complex jQuery hac ...

The functionality of aria-expanded is not functioning properly when set to false

Having trouble with the bootstrap accordion feature. When the page loads, the accordions are expanded by default instead of being collapsed. I want them to start collapsed and then expand when clicked. Here is the HTML code: <!DOCTYPE html> &l ...

The z-index property does not seem to apply to pseudo elements

I am facing an issue while trying to add a pseudo element after a div in my react project. Surprisingly, the code works perfectly fine in CodePen but fails to work on my local machine. I have applied z-index only in CodePen, which seems to resolve the issu ...

Chrome tab freezes when scrolling with the mouse

Working on a particularly interesting bug, I've managed to replicate it using a fiddle. The issue arises when the middle mouse button is clicked over the div element containing text, causing the pointer to become stuck. Is this possibly a browser bug ...

How to Achieve a Fixed Bottom Footer in Ember Framework

Hello, I am working on an Ember application and trying to implement a Sticky Footer feature. I followed a tutorial on Sticky Footer On CSS-Tricks which worked for me previously, but it seems to not work with Ember. Here is my CSS code: .mainFooter { ...

Tips for keeping the menu open even when you're not hovering over it with your cursor

I put together a stylish drop-down menu based on some web examples, but my manager pointed out that it can be inconvenient to use because the menu closes when the mouse moves off of it. I've tried various workarounds as outlined here, but none have in ...

The main menu items in jQuery do not display the child sub menu upon clicking

I'm currently in the process of creating a unique mobile menu for my Wordpress website, but I'm facing some challenges when it comes to displaying and hiding the sub-menu items. I've assigned the class name .menu-item-has-children as my sele ...

The height of the <div> element is not increasing along with the content inside. If I set the height to "auto

I encountered an issue with my webpage design. It has set dimensions with blue borders on the sides and bottom. The problem arises when I add Facebook comments to the page - as more comments are added, they extend beyond the bottom of the webpage, below ...

The close menu button is not functioning properly when clicked outside the menu - the buttonevent.matches is not recognized as a

I am encountering an issue with the dropdown menu that is not closing when clicking outside of the menu button. Despite having faced this problem before, I can't seem to find a solution now. Any help would be greatly appreciated as I am uncertain why ...

What is the best way to store checkbox statuses in local storage and display them again in a JavaScript to-do list?

I'm currently working on a to-do list application using basic JavaScript. One issue I'm facing is saving the checked status of the checkbox input element and displaying it again after the page is refreshed. Since I'm still learning JavaScrip ...

div with fixed position and scrollable content

I'm exploring ways to create a simple webpage layout inspired by the traditional index setup. The idea is to have a fixed header/navbar div that is 200px in height, with a second div below it containing scrollable content that fills the remaining vert ...

Issue with Font-Awesome icons failing to display properly when using the BootstrapCDN

Trying to integrate Font-Awesome icon fonts using the BootstrapCDN link with what seems like the latest version: <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> The link has been added to the <hea ...

Troubleshooting problems with spacing in CSS flexbox due to the gap property

Having some trouble with flexbox. The gap property is making the columns too wide when trying to create a simple 3 column row. I was under the impression that the gap value should not affect the width set. For example, using flex: 0 1 33.33% and gap 2rem ...

td having no line breaks causing text to extend beyond the cell

I have a challenge with using the nowrap property on td elements to ensure proper formatting of my tables. In the first table, everything wraps nicely, but in the second table, the content in the first "td" exceeds its designated space due to length. How c ...

Bootstrap version 5.3.0 has a unique behavior where dropdowns placed outside the collapsed area of the navbar will display the menu inside the navbar, rather than outside

Is there a way to fix the issue where the dropdown menu appears in the body of the navbar when it is collapsed? I have tried using attributes like data-bs-reference but couldn't find much information on how to resolve this. <nav class="navbar ...

Semantic UI allows for both left and right action input functionalities to be utilized

Is there a way to add actions on both ends of an input field? Here's what I've tried so far: <form class="ui form"> <div class="ui left action input"> <select class="ui compact selection dropdown" name="seats"> ...

Ways to eliminate the up and down arrow in the MUI number field

How can I remove the up and down arrow from the MUI number field? My current version is 5.3.0. Is it possible to achieve this using the sx prop? Learn more about the sx prop here <TextField sx={{...}} id="outlined-number" label="Nu ...

JS will reach its stopping point at the specified style.zIndex

I am currently in the process of setting up button elements. I have two scripts that correspond to different types of buttons - one script runs a simple collapse menu, while the other executes a more complex collapse by shifting depths and sliding one div ...

Utilizing CSS Grid to dynamically stretch and wrap rows based on adjacent siblings within a flat DOM structure

Looking for a way to create a grid layout that adjusts row sizes based on adjacent siblings. Interested in SCSS or CSS solutions using grid, flexbox, or other techniques. I am working with a dynamically generated list based on configurations. The length, ...