Answer the question
In order to leave comments, you need to log in
Recursion when calling method in jQuery plugin?
Based on this translation , I began to write a plugin (image slider).
In general, the point is not what the plugin does, but how.
I need to repeatedly call the same plugin method. But here I get an error. The algorithm in the method is as follows: Animate the DOM object -> auto-increment the variable in data -> delay -> call the same method.
On the second call to $(this) I have undefined. - Do not understand why.
But I have an assumption that it’s wrong to do this, I don’t have a very good algorithm. Please tell me how to write correctly. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Most likely you are calling the method like
methods.any();
methods.any.call(this);
I think you did something wrong in the first place. you should learn the JavaScript section about function context.
jsfiddle.net/kpVJv/ - out of curiosity, I sketched a simple example of a slider in the form of a jQuery plugin (the simplest, nothing interesting), but maybe you will find something interesting.
Without code, it's hard to say for sure, but first of all, you shouldn't use $(this), it's better to refer to the node more explicitly. In the case of an event, for example, through e.target
Is it not possible to refer to an object through this instead of $(this) inside the plugin, or am I confusing?
setTimeout("$('"+data.id+"').myPlugin('next')", data.timeout);
var myPlugin = $(data.id).myPlugin
setTimeout(function(){ myPlugin('next') }, data.timeout);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question