1

The animation in my .css file is called @keyframes scrollTextTwo{}. the code in my .js file is:

$(document).ready(function(){
  rightBox.style.animation = "scrollTextTwo 10s 1";
});

When I load the .html file in the browser it perfectly runs one time or it will run infinitely if i replace the "1": after the scrollTextTwo 10 with infinite. My question is how can I get a second object such as #leftBox from my .css file to animate ONLY after the #rightBox has completed its animation in the above example.

I have attached all three docs: html/css/.js with code pen just in case anyone wants to dive deep into the code.

http://codepen.io/hoyos/pen/dGMGbX

1
  • i made an error the next animation isnt "leftBox" its saposed to be rightBoxTwo, for anyone actualy looking at the codepen Commented Dec 17, 2015 at 15:02

1 Answer 1

2

You could listen to the animationend event. Use the .one() method to attach the event listener so that it only fires once. When the event is triggered, that means the animation has ended, which means that you can animate the other element in the callback.

Updated Example

$('#rightBox').css('animation', "scrollTextTwo 5s 1").one('animationend', function () {
  $('#leftBox').css('animation', "scrollTextTwo 5s 1");
});
Sign up to request clarification or add additional context in comments.

1 Comment

i copied $('#rightBox').css('animation', "scrollTextTwo 5s 1"); and tested to see if it would iterate once and it did so thx, but then i put $('#rightBox').css('animation', "scrollTextTwo 5s 1").one('animationend', function () { $('#rightBox').css('animation', "scrollTextTwo 5s 1"); }); and tested to see if it would iterate twice to then test it the next step and it would iterate at all

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.