-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgs_tabs.js
54 lines (47 loc) · 1.51 KB
/
gs_tabs.js
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
;(function ($) {
/**
* tabs组件
* @returns this;
*/
$.fn.gs_tabs = function (opts) {
opts = $.extend({
'title': 'li > a'
,'active': 'active'
,'content':'.gs-tab-content'
,'callback':''
}, opts);
var $this = $(this)
,$tab_title = $this.find(opts.title)
,idlist = [];
$tab_title.each(function(i){
idlist.push($(this).attr('href')); //记录id
});
/**
* 不是自己的隐藏掉
* @param {string} c id标记
* @returns null
*/
var hide_content = function(c){
for (i in idlist) {
if (idlist[i]!=c) {
$(idlist[i]).hide().removeClass(opts.active);
}
}
}
$tab_title.on('click',function(){
var showC = $(this).attr('href');
hide_content();
$(showC).show().addClass(opts.active);
//自定议结构需要把 active 写在自已无素上
if (opts.title != 'li > a') {
$(this).siblings().removeClass(opts.active).end().addClass(opts.active);
}else{
$(this).parent().siblings().removeClass(opts.active).end().addClass(opts.active);
}
//回调
opts.callback && opts.callback(this);
return false;
});
return this;
};
})(window.jQuery);