Bizarro Zeldman
Bizarro Zeldman

Reputation: 257

How to Sync CSS3 Animation Events and Event Listeners with jQuery

I am trying to figure out a solid, cross-(modern)browser method for using CSS3 Animation Events and Event Listeners to gain fine-tuned control over CSS3 animations. I know its possible to do this. Sadly it's just WAY beyond my capabilities at the moment, despite all the research I've done in the last 2-3 weeks.

Here is my jsfiddle on this so far: http://jsfiddle.net/mvkMH/23/

Here is what I'm trying to do: I have a <ul> with an id of #main containing <li>'s with a class of .box. When a user clicks on any .box it adds the .move-y class to ($this) - it also simultaneously adds the .move-x class to the remaining list items. When the user clicks another .box, all the existing .move-y and .move-x classes are replaced with .move-y-rvs and .move-x-rvs classes. All the while using CSS3 Animation events to keep everything perfectly synced up.

Why CSS3 Animation Events?

Here is the way the script should work in my mind - I just couldn't get it to work in real life ;-)

  1. Upon clicking the .box element, Check #main for any .move-x and .move-y classes

  2. If .move-x and .move-y classes are detected:

    • replace those classes with move-x-rvs and .move-y-rvs
    • Attach css Animation Event listeners to the elements with .move-x-rvs and .move-y-rvs classes
    • On AnimationEnd Event remove the .move-x-rvs and .move-y-rvs classes
    • Set AnimationName to an empty string (this resets the css3 animation to play again if clicked again)
    • Now add the .move-y class to $(this)
    • Add the .move-x class to all the other remaining list items
  3. If .move-x and .move-y are not detected:

    • Add the .move-y class to $(this)
    • Add the .move-x class to all the other remaining list items

4 - The Animation Event listener functionality should append the prefixes for modern browsers (like in this example - How do I re-trigger a WebKit CSS animation via JavaScript?)

Again, Here is my jsfiddle on this so far: http://jsfiddle.net/mvkMH/23/

Any help you folks could provide would be greatly appreciated!

Thanks in advance! Bizarro.Z

Upvotes: 8

Views: 2808

Answers (2)

create a jQuery function that changes the class of an element with a specific ID. Then you can sync them by calling the function in the jQuery code.

Upvotes: 0

Manuel van Rijn
Manuel van Rijn

Reputation: 10315

have a look at the jquery.transit plugin

Upvotes: 0

Related Questions