0
我很新的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);
任何幫助,非常感謝!謝謝!
感謝您回覆@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