DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> 基於jQuery的Tab選項框效果代碼(插件)
基於jQuery的Tab選項框效果代碼(插件)
編輯:JQuery特效代碼     
代碼如下:
/**
* jQuery插件
* Author: [email protected]
* Date : 2011-02-25
* Params:
* defaults:{
currentClass:當前樣式,
trigger:觸發方式,
callBack:回調函數,
auto:是否自運行,
detay:延遲時間,
index:當前位置
* }
* 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();
//移至當前位置
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);
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved