基于jQuery的Tab選項框效果代碼(插件)
更新時間:2011年03月01日 23:33:15 作者:
依據(jù)className實現(xiàn)的Tab選項框,支持多個tab,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
/**
* jQuery插件
* Author: purecolor@foxmail.com
* Date : 2011-02-25
* Params:
* defaults:{
currentClass:當(dāng)前樣式,
trigger:觸發(fā)方式,
callBack:回調(diào)函數(shù),
auto:是否自運行,
detay:延遲時間,
index:當(dāng)前位置
* }
* Return: null
* Note : Tab選項框插件
*
*/
(function($){
$.fn.extend({
tabBuild:function(options){
return $(this).each(function(){
var defaults={
currentClass:"currentOne",
trigger:"mouseover",
callBack:null,
auto:true,
detay:3000,
index:0
}
var params=$.extend(defaults,options);
var $this=$(this);
var items=$('.tab-menu',$this),i=0;
var autoTimer,curro=0;
items.each(function(){
$(this).data('lvl',i);
if(i==params.index){
$('.tab-content',$this).eq(i).show();
$(this).addClass(params.currentClass);
}else{
$('.tab-content',$this).eq(i).hide();
}
i++;
$(this).bind(params.trigger,function(e){
//移除自動運行
if(params.auto){
if(autoTimer) clearInterval(autoTimer);
}
move($(this).data("lvl"));
//清除冒泡
if (e.stopPropagation) {
e.stopPropagation(); // for Mozilla and Opera
}
else if (window.event) {
window.event.cancelBubble = true; // for IE
}
});
});
//移動播放
function move(i){
//移除上一個效果
items.eq(params.index).removeClass(params.currentClass);
$('.tab-content',$this).eq(params.index).hide();
//移至當(dāng)前位置
items.eq(i).addClass(params.currentClass);
$('.tab-content',$this).eq(i).show();
params.index=i;
}
//自動運行
function auto(){
if(params.auto){
autoTimer=setInterval(function(){
curro=(params.index>=2)?0:(params.index+1);
move(curro);
},params.detay);
}else{
if(autoTimer) clearInterval(autoTimer);
}
}
auto();
});
}
});
})(jQuery);
相關(guān)文章
基于jQuery實現(xiàn)文本框只能輸入數(shù)字(小數(shù)、整數(shù))
在實際應(yīng)用中,文本框中有時候只能夠允許輸入整數(shù),但是有時候可能更為"博愛"一點,可以允許輸入浮點數(shù),下面就通過實例代碼介紹一下如何利用jquery實現(xiàn)此功能2016-01-01
jQuery EasyUI Layout實現(xiàn)tabs標(biāo)簽的實例
這篇文章主要介紹了jQuery EasyUI Layout實現(xiàn)tabs標(biāo)簽的實例的相關(guān)資料,希望通過本文能幫助到大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09
jquery點擊實現(xiàn)升序降序圖標(biāo)切換
這篇文章主要為大家詳細(xì)介紹了jquery點擊實現(xiàn)升序降序圖標(biāo)切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-07-07
jquery點擊回車鍵實現(xiàn)登錄效果并默認(rèn)焦點的方法
下面小編就為大家分享一篇jquery點擊回車鍵實現(xiàn)登錄效果并默認(rèn)焦點的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03

