jquery.tabs_wev8.js
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* =================================================
// jQuery Tabs Plugins 1.0
// author:chenyg@5173.com
// URL:http://stylechen.com/jquery-tabs.html
// 4th Dec 2010
// =================================================*/
;(function($){
$.fn.extend({
Tabs:function(options){
// 澶勭悊鍙傛暟
options = $.extend({
event : 'mouseover',
timeout : 0,
auto : 0,
callback : null,
getLine:0,
topHeight:0
}, options);
var self = $(this),
tabBox = self.children( 'div.tab_box' ).children( 'div' ),
menu = self.children( 'ul.tab_menu' ),
items = menu.find( 'li' ),
timer,
$magicLine;
var tabHandle = function( elem ){
elem.siblings( 'li' )
.removeClass( 'current' )
.end()
.addClass( 'current' );
tabBox.siblings( 'div' )
.addClass( 'hide' )
.end()
.eq( elem.index() )
.removeClass( 'hide' );
if(options.getLine){
$magicLine
.width($magicLine.siblings(".current").width()-16)
.css("left", $magicLine.siblings(".current").position().left+8)
.data("origLeft", $magicLine.position().left+8)
.data("origWidth", $magicLine.width()-16);
}
},
delay = function( elem, time ){
time ? setTimeout(function(){ tabHandle( elem ); }, time) : tabHandle( elem );
},
start = function(){
if( !options.auto ) return;
timer = setInterval( autoRun, options.auto );
},
autoRun = function(){
var current = menu.find( 'li.current' ),
firstItem = items.eq(0),
len = items.length,
index = current.index() + 1,
item = index === len ? firstItem : current.next( 'li' ),
i = index === len ? 0 : index;
current.removeClass( 'current' );
item.addClass( 'current' );
tabBox.siblings( 'div' )
.addClass( 'hide' )
.end()
.eq(i)
.removeClass( 'hide' );
};
items.bind( options.event, function(){
delay( $(this), options.timeout );
if( options.callback ){
options.callback( $(this).parent().parent());
}
});
if( options.auto ){
start();
self.hover(function(){
clearInterval( timer );
timer = undefined;
},function(){
start();
});
}
var tabboxheight = $(".tab_box").css("height");
if(tabboxheight.indexOf("px")>0){
tabboxheight = tabboxheight.substring(0,tabboxheight.indexOf("px"));
}
$(".tab_box").css("height",tabboxheight-options.topHeight);
if(options.getLine){
var $el, leftPos, newWidth,
$mainNav = $(".tab_menu");
$mainNav.append("<li class='magic-line'></li>");
$magicLine = $(".magic-line");
$magicLine
.width($(".current").width()-16)
.css("left", $(".current").position().left+8)
.data("origLeft", $magicLine.position().left+8)
.data("origWidth", $magicLine.width()-16);
$(".tab_menu li").hover(function() {
/*$magicLine = $(this).siblings(".magic-line");
$el = $(this);
leftPos = $el.position().left+8;
newWidth = $el.width()-16;
$magicLine.stop().animate({
left: leftPos,
width: newWidth
});*/
}, function() {
/*if(!$magicLine.data("origLeft"))$magicLine.data("origLeft",0);
$magicLine.stop().animate({
left: $magicLine.data("origLeft"),
width: $magicLine.siblings(".current").width()-16
}); */
});
}
return this;
}
});
})(jQuery);