为了账号安全,请及时绑定邮箱和手机立即绑定

为啥提示tabItems.size is not a function

https://img1.sycdn.imooc.com//5d65ed670001c4f312360304.jpg

(function($){

var Tab = function(tab) {

var _this = this;

this.tab = tab;


//默认配置参数

this.config = {

"triggerType": "mouseover", //鼠标的触发类型,click/mouseover

"effect": "default",   //内容切换效果,无效果/淡入淡出

"invoke": 1,    //默认显示第几个tab

"auto": false    //tab是否自动切换

}

//如果传了配置参数,就覆盖默认配置参数

if(this.getConfig()){

$.extend(this.config, this.getConfig())

}


this.tabItems = this.tab.find("ul.tab-nav li")

this.contentItems = this.tab.find("div.content-wrap .content-item")

var config = this.config;

if(config.triggerType === "click"){

this.tabItems.bind(config.triggerType,function(){

_this.invoke($(this))

})

}else if(config.triggerType === "mouseover" || config.triggerType != "click"){

this.tabItems.on('mouseover',function(){

_this.invoke($(this))

})

}


//自动切换

if(config.auto){

//定义一个全局定时器

this.timer = null;

//计数器

this.loop = 0;

this.autoplay()

}

};


Tab.prototype = {

//获取配置参数

getConfig:function() {

var config = this.tab.data('config')    //对象

if(config && config!=""){

return config

}else{

return null

}

},

//切换

invoke:function(currentTab) {

var _this = this;

var index = currentTab.index()

//切换选项卡

currentTab.addClass('actived').siblings().removeClass('actived')

//切换内容(根据不同effect效果)

var effect = this.config.effect;

var contentItems = this.contentItems;

if(effect === "default" || effect != "fade"){

contentItems.eq(index).addClass('current').siblings().removeClass('current')

}else if(effect === "fade"){

contentItems.eq(index).fadeIn().siblings().fadeOut()

}

},

//自动切换

autoplay:function(){

var _this = this,

tabItems = this.tabItems,

tabLength = tabItems.size(),

config = this.config


this.timer = setInterval(function(){

_this.loop++;

if(_this.loop >= tabLength){

_this.loop = 0

}

tabItems.eq(_this.loop).trigger(config.triggerType)

}, config.auto)


}

};


window.Tab = Tab;

})(jQuery)


正在回答

1 回答

jquery 1.8后 length取代了 size()  ,因为length不需要返回一个函数调用,更优秀。 用tabItems.length。 

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为啥提示tabItems.size is not a function

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信