Skip to content
Advertisement

issue with line through animation

I want to create a simple line through animation and so far I’m here:

JavaScript
JavaScript

As you see everything works fine except two things:

  1. Now we can see the line at first then it hides and starts the animation, I want to see only the animated line.

  2. I want to initiate the animation using javascript… but with this pseudo-element (after) it seems complicated!

Advertisement

Answer

You can fix your animation using animation-fill-mode:

JavaScript

To trigger your animation, just add the strikethrough class. The thing where I think this won’t work is when you have a multiline text, as your ::after won’t cover that.

JavaScript
JavaScript
JavaScript

Personally, I would take this simpler tack to reduce the amount of actual objects on screen, and the amount of code, by using a background image to scale. If cleverly set up, you could even multi-line this (by making the background the line height and having a middle pixel in it – and with SVGs you could ensure it was only 1px regardless of the stretching etc…).

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement