jquery插件选项没有阅读
问题描述:
我很新的jQuery和我创建我的第一个插件,但遇到问题。我能够很好地工作,但是当我添加选项到我的函数时,它似乎没有正确读取它。例如我有slideshowTransition选项,但它似乎并没有在我的rotateImages函数中读取它。我可以将它输出到控制台,但不知道它为什么不能读取。请参阅下面的代码:jquery插件选项没有阅读
(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]: http://jsfiddle.net/kDg3A/1/
我刚才添加的代码看看供你参考。
感谢您回复@Ravi,但是当我在这行代码中添加选项** nextPhoto.css({opacity:0}).addClass('current')。animate({opacity:1.0},settings。 slideshowTransition **“settings.slideshowTransition”选项没有阅读任何想法为什么? – 2013-04-09 01:42:52
hi delmon, 我不确定,为什么你没有得到settings.slideshowTransition的价值,你可以发布你的代码和相关的html并在jsfiddle函数调用的东西,将有一个看看,并帮助你什么我可以 – 2013-04-09 04:51:54
hey @ravi。对不起,我还没有能够发布到现在。这是我的代码在jsfiddle:http://jsfiddle.net/ghowell/d5P9n /。我可以在控制台上打印** settings.slideshowTransition **的值,但是我的代码的最后一行以nextPhoto.css开头,无法读取它。 – 2013-04-20 14:35:34