For those of you already familiar with using jQuery, using the jQuery.fn.stop
function is a simple and common thing when working with different animations on a common element.
My question is about creating jQuery extensions. I have already developed jQuery plugins for some time and to develop any extensions I use an own standard based on an international standard created by Addy Osmani where I made some changes.
This standard is for the developer to use a plugin, do not go through some problems that could occur in several different situations and browsers or even to avoid certain types of conflicts with names of variables, functions and events, among others.
When a user uses the jQuery.fn.off
function, 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 specific plugin, 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 delegated with something close to it:
jQuery(document).off('.customNamespace');
My question is about doing something similar, but with jQuery animations.
Suppose I have a plugin that moves through an animation the vertical and horizontal scroll bars of an element in the DOM. When the user triggers an undetermined event I want to for example stop the animation only vertically while the horizontal scrolling continues to move. The use of jQuery.fn.stop
does not help me in this question since it stops 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 scrollTop only and continue with the scrollLeft animation announced in the same instance of the jQuery.fn.animate
function? 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 if I have complicated a question that maybe has an easy resolution for someone or if it was clear enough, but in case of doubts, I keep an eye on the comments.