3
For those who are already used to using jQuery, use the function jQuery.fn.stop
is something simple and very common when we work with different animations in a common element.
My doubt is focused on creating jQuery extensions. I have been developing jQuery plugins for some time and to develop any extension I use my own standard based on an international standard created by Addy Osmani where I made some changes.
This standard serves to the developer who uses a plugin, not go through some problems that could occur in various situations and different browser or even to avoid certain types of conflicts with variable names, functions and events among others.
When a user uses the function jQuery.fn.off
for example, it removes a chain of delegated events with jQuery functions (jQuery.fn.on
for example). In case the user needs to remove only the events delegated by a plugin in specific, the correct one in a pattern would be to use a namespace as in the example below:
jQuery(document).on('click.customNamespace', jQuery.noop);
So the developer could remove only the events that the plugin has delegated with something close to this:
jQuery(document).off('.customNamespace');
My doubt is about performing something similar, but with jQuery animations.
Suppose I have a plugin that moves through an animation the vertical and horizontal scrolling bars of an element in the DOM. When the user fires an undetermined event I want for example to stop the animation only vertically while the horizontal scrolling continues to move. The use of jQuery.fn.stop
does not help me in this matter since it for all animations of the element (at least not in a way that I know).
The question then would be: How can I stop only certain animation or part of an animation? How to stop only "scrollTop" and continue with the animation of "scrollLeft" announced in the same instance of the function jQuery.fn.animate
? And if this is possible in some way that I do not know, it would be possible to create a kind of namespace for this as I exemplified with events above (something like jQuery(document).stop('.myNamespace')
)?
I do not know whether I have complicated a question too much that may be easily resolved by someone or whether I have been clear enough, but in case of doubt I am looking at the comments.
Very interesting, I had already worked with queues of animations but was unaware of this functionality. I just didn’t think that the example you found about instantiating a new animation with duration 0 applies in a good practice, although it is a good way out if there is no other way to do it. Thank you very much!
– Diego Lopes Lima