0

I have created an animation similar to described here: https://css-tricks.com/animating-the-content-property/

I can pause animation of movement but for some reason i cannot pause the animation of "content" with javascript (jQuery). I can set it default as paused but I cannot pause it after it starts running.

@-webkit-keyframes changeLetter {
  0% {
    content: "A";
  }
  50% {
    color: white;
  }
  100% {
    content: "B";
  }
}

@keyframes changeLetter {
  0% {
    content: "A";
  }
  50% {
    color: white;
  }
  100% {
    content: "B";
  }
}

@-webkit-keyframes move {
  0% {
    left: 50px;
  }
  100% {
    left: 100px;
  }
}

@keyframes move {
  0% {
    left: 50px;
  }
  100% {
    left: 100px;
  }
}

.element:after {
  -webkit-animation: changeLetter 3s linear infinite alternate;
  animation: changeLetter 3s linear infinite alternate;
  content: "A";
}

.test{
  position: relative;
  left: 0px;
  top: 0px;
  width: 50px;
  height: 50px;
  background-color: red;
}

.test {
  -webkit-animation: move 1s linear infinite alternate;
  animation: move 1s linear infinite alternate;
}

.paused{
    animation-play-state: paused !important; 
    -webkit-animation-play-state: paused !important;
}

$("#play").click(function() {
    $('.animation').toggleClass('paused');
});

<div class="animation element"></div>
<div class="animation test"></div>
<button id="play" type="button">Pause/Play</button>

See the fiddle here: https://jsfiddle.net/eLt8zd33/1/

This is a very small code sample of my project.

1 Answer 1

3

Add the pseudo to your style for .paused

.paused, .paused:after{
    -webkit-animation-play-state: paused !important;
    animation-play-state: paused !important; 
}

Since your animation is in the pseudo, adding .paused to the main without this extension won't have any effect

Sign up to request clarification or add additional context in comments.

1 Comment

One should always put prefixed properties first ;) ... upvoted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.