How do I make custom functions chain-able with jQuery's?

Posted by sergio on Stack Overflow See other posts from Stack Overflow or by sergio
Published on 2012-11-11T10:58:55Z Indexed on 2012/11/11 10:59 UTC
Read the original article Hit count: 213

I need a "callfront" or "precall" (the opposite of "callback" ¿?) to add in MANY places before an animation occurs in an existing plugin, To be used like e.g.

$(some_unpredictable_obj).preFunct().animate(…

The problem is, as I said they are MANY places, and all of them are different animations, on different objects.

I can TELL where all of them occur, but I don't want to add over and over the same code.

I actually have to add both a function before and after those animations, but I think I can use the callback for all of them.

In a perfect world, I'd like to replace every

animate(property, duration)

by

preFunct().animate(property,duration).postFunct()

preFunct and postFunct don't need parameters, since they are always the same action, on the same object.

This could be an amazing addition to "jQuery" (an easy way to jQuerize custom functions to be added to the normal chain (without messing with queues)

I found this example but it will act on the applied element, and I don't want that because, as I said above, all the original animations to be added to are on different elements.

I also found jQuery.timing, but it looks cooler the chain-able function :)

Thanks.

© Stack Overflow or respective owner

Related posts about callback

Related posts about queue