ホームページ  >  記事  >  ウェブフロントエンド  >  jQuery_jquery に基づくタブ オプション ボックス効果コード (プラグイン)

jQuery_jquery に基づくタブ オプション ボックス効果コード (プラグイン)

WBOY
WBOYオリジナル
2016-05-16 18:09:591065ブラウズ
复制代代码如下:

/**
* jQuery プラグイン
* 著者: purecolor@foxmail.com
* 日付: 2011-02-25
* パラメータ:
* デフォルト:{
currentClass: 現在のスタイル、
trigger: トリガーモード、
callBack: コールバック関数、
auto: 自動実行するかどうか、
detay: 遅延時間、
index: 現在位置
* }
* 戻り値: null
* 注: タブ オプション ボックス プラグイン
*
*/
(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; =0;
items.each(function(){
$(this).data('lvl',i);
if(i==params.index){
$(' .tab-content',$this).eq(i).show();
$(this).addClass(params.currentClass);
$('.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() // Mozilla および Opera 用
}
else if (window.event) {
window.event; .cancelBubble = true; // IE の場合
}
})
//移動播放
function move(i){
//移除上一个結果
items.eq(params.index).removeClass(params.currentClass);
$('.tab-content',$this).eq(params.index).hide();
//移動至当前位置
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);

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。