Tab切換組件(選項(xiàng)卡功能)實(shí)例代碼
直接貼代碼里面有注釋:
/**
* 簡單的Tab切換
* 支持可配置項(xiàng) 如下參數(shù)
*/
function Tab(){
this.config = {
type : 'mouseover', //類型 默認(rèn)為鼠標(biāo)移上去
autoplay : true, // 默認(rèn)為自動(dòng)播放
triggerCls : '.list', // 菜單項(xiàng)
panelCls : '.tabContent', // 內(nèi)容項(xiàng)
index : 0, // 當(dāng)前的索引0
switchTo : 0, // 切換到哪一項(xiàng)
interval : 3000, // 自動(dòng)播放間隔時(shí)間 默認(rèn)為3 以s為單位
pauseOnHover : true, // 鼠標(biāo)放上去是否為暫停 默認(rèn)為true
current : 'current', // 當(dāng)前項(xiàng)添加到類名
hidden : 'hidden', // 類名 默認(rèn)為hidden
callback : null // callback函數(shù)
};
this.cache = {
timer : undefined,
flag : true
};
}
Tab.prototype = {
init: function(options){
this.config = $.extend(this.config,options || {});
var self = this,
_config = self.config;
self._handler();
},
_handler: function(){
var self = this,
_config = self.config,
_cache = self.cache,
len = $(_config.triggerCls).length;
$(_config.triggerCls).unbind(_config.type);
$(_config.triggerCls).bind(_config.type,function(){
_cache.timer && clearInterval(_cache.timer);
var index = $(_config.triggerCls).index(this);
!$(this).hasClass(_config.current) &&
$(this).addClass(_config.current).siblings().removeClass(_config.current);
$(_config.panelCls).eq(index).removeClass(_config.hidden).siblings().addClass(_config.hidden);
// 切換完 添加回調(diào)函數(shù)
_config.callback && $.isFunction(_config.callback) && _config.callback(index);
});
// 默認(rèn)情況下切換到第幾項(xiàng)
if(_config.switchTo) {
$(_config.triggerCls).eq(_config.switchTo).addClass(_config.current).siblings().removeClass(_config.current);
$(_config.panelCls).eq(_config.switchTo).removeClass(_config.hidden).siblings().addClass(_config.hidden);
}
// 自動(dòng)播放
if(_config.autoplay) {
start();
$(_config.triggerCls).hover(function(){
if(_config.pauseOnHover) {
_cache.timer && clearInterval(_cache.timer);
_cache.timer = undefined;
}else {
return;
}
},function(){
start();
});
}
function start(){
_cache.timer = setInterval(autoRun,_config.interval);
}
function autoRun() {
if(_config.switchTo && (_config.switchTo == len-1)){
if(_cache.flag) {
_config.index = _config.switchTo;
_cache.flag = false;
}
}
_config.index++;
if(_config.index == len) {
_config.index = 0;
}
$(_config.triggerCls).eq(_config.index).addClass(_config.current).siblings().removeClass(_config.current);
$(_config.panelCls).eq(_config.index).removeClass(_config.hidden).siblings().addClass(_config.hidden);
}
}
};
頁面上調(diào)用方式如下:
$(function(){
new Tab().init({
switchTo: 1,
callback: function(index){
console.log(index);
}
});
});
- JavaScript版TAB選項(xiàng)卡效果實(shí)例
- jQuery自動(dòng)切換/點(diǎn)擊切換選項(xiàng)卡效果的小例子
- jsp js鼠標(biāo)移動(dòng)到指定區(qū)域顯示選項(xiàng)卡離開時(shí)隱藏示例
- jq選項(xiàng)卡鼠標(biāo)延遲的插件實(shí)例
- jQuery學(xué)習(xí)筆記(3)--用jquery(插件)實(shí)現(xiàn)多選項(xiàng)卡功能
- 自定義jQuery選項(xiàng)卡插件實(shí)例
- jquery多選項(xiàng)卡效果實(shí)例代碼(附效果圖)
- android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
相關(guān)文章
Bootstrop實(shí)現(xiàn)多級(jí)下拉菜單功能
Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它簡潔靈活,使得 Web 開發(fā)更加快捷。本文重點(diǎn)給大家介紹bootstrap實(shí)現(xiàn)多級(jí)下拉菜單功能的實(shí)例代碼,感興趣的朋友一起學(xué)習(xí)吧2016-11-11jQuery 獲取和設(shè)置select下拉框的值實(shí)現(xiàn)代碼
jQuery獲取和設(shè)置select下拉框值的實(shí)現(xiàn)代碼。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11關(guān)于HTML5的data-*自定義屬性的總結(jié)
大家總是習(xí)慣使用HTML標(biāo)簽添加自定義屬性來存儲(chǔ)和操作數(shù)據(jù),所以才在HTML5規(guī)范里增加了一個(gè)自定義data屬性,這樣使用更便捷,一起跟隨小編過來看看吧2018-05-05原生Aajax 和jQuery Ajax 寫法個(gè)人總結(jié)
AJAX:即“Asynchronous Javascript And XML”(異步JavaScript和XML),是指一種創(chuàng)建交互式網(wǎng)頁應(yīng)用的網(wǎng)頁開發(fā)技術(shù)。本文重點(diǎn)給大家介紹原生Aajax 和jQuery Ajax 個(gè)人總結(jié),一起看看吧2017-03-03jQuery插件HighCharts繪制的2D堆柱狀圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts繪制的2D堆柱狀圖效果,結(jié)合完整實(shí)例形式分析了jQuery插件HighCharts繪制2D柱狀圖的實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03把jquery 的dialog和ztree結(jié)合實(shí)現(xiàn)步驟
首先準(zhǔn)備好juqury-ui、ztree 的js文件和css 文件,接下來的步驟祥看本文希望對(duì)大家有所幫助2013-08-08jquery插件tytabs.jquery.min.js實(shí)現(xiàn)漸變TAB選項(xiàng)卡效果
這篇文章主要介紹了jquery插件tytabs.jquery.min.js實(shí)現(xiàn)漸變TAB選項(xiàng)卡效果,實(shí)例分析了tytabs.jquery.min.js插件實(shí)現(xiàn)tab選項(xiàng)卡切換效果的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08