jquery插件选项不读

时间:2013-04-07 23:16:14

标签: jquery jquery-plugins

我对jquery很新,我正在创建我的第一个插件,但遇到了问题。我能够让它工作正常但是当我在我的功能中添加选项时,它似乎没有正确读取它。例如,我有 slideshowTransition 选项,但它似乎没有在我的 rotateImages 函数中读取它。我可以将它输出到控制台,但不知道为什么它不读。请参阅以下代码:

(function($){
 $.fn.imageRotator = function(config, slideshowSpeed) {

$.imageRotator = {
    defaults: {
    slideshowSpeed: '3000',
            slideshowTransition: '4000'
    }
};

settings = $.extend({}, $.imageRotator.defaults, config); 

//loop back to the top once rotateimages function is complete       
setInterval(rotateImages, settings.slideshowSpeed); 

function rotateImages(config){

var currentPhoto = $("#photo_slideshow .current");
var nextPhoto = currentPhoto.next();

//used to loop back to the top once the last image is finished
if(nextPhoto.length == 0){
    nextPhoto = $("#photo_slideshow div:first");
}

currentPhoto.removeClass('current').addClass('previous');

console.log(settings.slideshowSpeed);


//take what's next make it visible and move it on top
nextPhoto.css({ opacity: 0 }).addClass('current').animate({ opacity: 1.0 }, settings.slideshowTransition, 


    //callback function to drop photo down to the bottom of the z-index
    function(){

    currentPhoto.removeClass('previous');

    }
)
};
//end rotate images function

};

})(jQuery);

非常感谢任何帮助!谢谢!

1 个答案:

答案 0 :(得分:1)

根据我对您的问题的理解,您在调用插件函数时遇到问题,如果是这样,请查看此链接

[1]: http://jsfiddle.net/kDg3A/1/

我刚刚添加了代码供您参考。