0

我对 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);

任何帮助是极大的赞赏!谢谢!

4

1 回答 1

1

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

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

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

于 2013-04-08T09:12:43.567 回答