0
我写了下面的jQuery插件:无限递归
(function($){
$.fn.imageSlide = function(options){
$(this).imageSlide.nextSlide();
console.log("imageslide");
};
$.fn.imageSlide.nextSlide = function(){
console.log("nextslide");
$this = $(this);
};
})(jQuery);
一些背景资料:
我想要的图像滑块插件,以交叉衰减的背景(由于性能原因我不能使用Supersized插件)。我想向用户公开几个函数:imageSlide插件“构造函数”和其他一些函数,例如imageSlide.nextSlide
和imageSlide.previousSlide
,以使用户能够从插件外部执行这些操作。
imageSlide
函数需要调用imageSlide.nextSlide function
来滑入(或淡入)第一个图像。
问题:
看来,线$this = $(this);
触发imageSlide.nextSlide
功能的无限递归。
- 这是怎么发生的?
- 看来
$.fn.imageSlide.nextSlide = function(){};
不是在jQuery插件中公开另一个函数的正确方法。我该如何做到这一点?
这是否返回一个jQuery对象?我想直接在jQuery对象上调用子函数,如下所示:'$('#gallery')。imageSlide.nextSlide()';这样我只会污染我的插件的一个“名称空间”(imageSlide),但我不需要跟踪我创建的图像滑块。 – Scharrels 2010-07-25 20:14:20
是的,你可以使用'$('#gallery')。imageSlide()。nextSlide();'链接它们,但是会创建一个新的实例。 – David 2010-07-25 20:26:00