我编写了以下 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 插件中公开另一个函数的正确方法。我该怎么做?