jQuery.animate() with css class only, without explicit styles

Jquery

Jquery Problem Overview


Using JQuery animate I would like to operate with css classes, defined somewhere in .css file, not to have to give all styles params to jquery.animate() explicitly.

I can create a fake (e.g. invisible) element with such a class, read its css properties and give them to jquery.animate() - does anybody know a better way?

Jquery Solutions


Solution 1 - Jquery

The jQueryUI provides a extension to animate function that allows you to animate css class.

edit: Example here

There are also methods to add/remove/toggle class which you might also be interested in.

Solution 2 - Jquery

Weston Ruther built a similar thing using the WebKit proposal for css transitions:

http://weston.ruter.net/projects/jquery-css-transitions/

This implementation might be useful for you.

Solution 3 - Jquery

Check out James Padolsey's animateToSelector

> Intro: This jQuery plugin will allow > you to animate any element to styles > specified in your stylesheet. All you > have to do is pass a selector and the > plugin will look for that selector in > your StyleSheet and will then apply it > as an animation.

Solution 4 - Jquery

In many cases you're better off using CSS transitions for this, and in old browsers the easing will simply be instant. Most animations (like fade in/out) are very trivial to implement and the browser does all the legwork for you. https://developer.mozilla.org/en/docs/Web/CSS/transition

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrudnevView Question on Stackoverflow
Solution 1 - JqueryJakub ArnoldView Answer on Stackoverflow
Solution 2 - JqueryScharrelsView Answer on Stackoverflow
Solution 3 - JqueryredsquareView Answer on Stackoverflow
Solution 4 - JqueryDominicView Answer on Stackoverflow