零捱科技网
您的当前位置:首页jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能_jquery

jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能_jquery

来源:零捱科技网


在Web中用到多选项卡功能的网站有很多,比如163和126邮箱,用过的人知道。本人在那么多的类似插件中,目前碰到这个比较好,花了点时间调试出来了,请看效果图:


这款插件叫jqueryMagicTabs,上图实现了基本功能,如添加选项卡,选择指定的选项卡。当添加的选项卡超过一定长度时会出现左右滑动的按钮,同时支持鼠标滑动选项卡。

这段代码如下所示:
代码如下:
<%@ page language="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>




MagicTabs的基础用法











$(function(){
var dd = [], i=0;
for(i=0; i<10; i++){
var a = {
code: 'tab' + i,
title: '选项卡 ' + i,
closeable: i>0,
el: '选项卡 ' + i // You can put anything here
};
dd.push(a);
}
var tabs = $('.tabs');
tabs.mac('tabs', {
tabWidth: 80, //Use fix width
items: dd,
onCloseTab: function(me, c, a){
tnCbx.find('[value=' + c + ']').remove();
return true;
}
}).selectFirst();
var thd = tabs.children('.head'), thm = thd.children('.main');
thd.mousewheel(function(e, delta, deltaX, deltaY){
thm.scrollLeft(thm.scrollLeft() - deltaY * 40);
return false;
});
//切换选择的选项卡
var tnCbx = $('#tabNoCbx').change(function(){
tabs.select($(this).val());
});
App.options(tnCbx, {
data: dd,
keyField: 'code',
render: function(r){
return r.title;
}
});
//添加选项卡
var atBtn = $('#addTabBtn').click(function(){
var a = tabs.addTab({
code: 'tab' + i,
title: '选项卡 ' + i,
closeable: i>0,
el: '选项卡 ' + i // You can put anything here
});
tabs.select('tab' + i);
tnCbx.append('+ i + '">选项卡 ' + i + '');
i++;
});
});






请选择:


添加选项卡





整个工程的目录如下所示:

本插件下载地址是http://boarsoft.com/cn/,里面还有很多优秀的插件,感兴趣可以自己练习下。

显示全文