我正在尝试创建自己的插件。但是我把事情弄好了。 当我试图在里面穿行时,它会出现。每个事情都会出错。
我试图通过淡化每隔6秒进入下一个项目。
jQuery(function($){
$.fn.rotator = function(options){
this.each(function() {
var container = $(this);
var images = container.children();
//Set the opacity of all images to 0
images.css({opacity: 0.0});
//Get the first image and display it (gets set to full opacity)
$('div:first',this).css({opacity: 1.0}).addClass('show');
//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
var obj = $(this);
setInterval(nextimage(obj),6000);
});
};
// rotate function
function nextimage(obj) {
var container = $(obj);
var images = container.children();
//Get the current image
var current = (images.hasClass('show')? images.hasClass('show') : images.first());
//Get next image, when it reaches the end, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('show')) ? images.first() :current.next()) : images.first());
//Set the fade in effect for the next image, the show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
};
});
$(document).ready(function(){
$("#bg").rotator({
})
});
我得到的错误是: current.next不是函数 第35行
第35行=
var next = ((current.next().length) ? ((current.next().hasClass('show')) ? images.first() :current.next()) : images.first());
有人能告诉我我做错了吗?
答案 0 :(得分:1)
第31行:
var current = (images.hasClass('show')? images.hasClass('show') : images.first());
current
要么被赋予布尔值,要么被赋予jQuery对象。我的猜测是当current
获得布尔值(由current.next().length
返回零引起)时抛出错误。 .next()
是一个jQuery方法,它不能在布尔值上调用。