Jquery tabins tabbox implementation code

Source: Internet
Author: User

I checked out the official JQ plug-in documentation (http://docs.jquery.com/Plugins/Authoring) and a plug-in a developed pattern written by Mike alsup recommended in this document. English is not very good, but I still try to see it (he is not happy to learn knowledge and practice English). tabbox is a debut.

As the name suggests, this plug-in is convenient to generate a "box" with the tab function. See the figure to understand

This function is very popular on the webpage, regardless of the front-end.

Here, I first provide three parameters for custom plug-ins,

CopyCode The Code is as follows: $. FN. tabbox. defaults = {
Width: 260,
Height: 200,
Basepath: "tabbox /"
};

Width and height define the width and height of the box. basepath is used to define the relative path of the page to the plug-in folder using the plug-in. This option is used only when it appears. Because an image is used in the tab style, you must have a baseline path to find the image path correctly. This also references the practice of a plug-in called jqtransform (http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/), which also has a parameter to specify the location of the image folder. Of course, there is another way, is to webui (http://www.jqueryui.com/) The same style written to the CSS file, so the image reference is first on the path with the CSS file, these two are components of the plug-in, and their relative strength remains unchanged. Therefore, you do not need to provide this path. This method is not used because the plug-in uses less styles.

The principle of the plug-in is very simple. The core function is a render (), which is used to render the tab style:

Copy code The Code is as follows: $. FN. tabbox. Render = function (){
$ (". Tabbox" ).css ({
Width: $. FN. tabbox. defaults. Width + "PX ",
Height: $. FN. tabbox. defaults. height + "PX ",
Position: "relative ",
Border: "1px # CCC solid ",
Background: "URL (" + $. FN. tabbox. defaults. basepath + "tabhead.gif) top left repeat-X"
});
$ (". Tabbox H2"). Each (function (I ){
Certificate (this).css ({
Width: "80px ",
Height: "30px ",
Position: "absolute ",
"Border-top": "NONE ",
Cursor: "Pointer ",
Left: 10 + (I * 80 ),
Background: "URL (" + $. FN. tabbox. defaults. basepath + "tabnormal.gif) Top right no-repeat ",
"Text-align": "center ",
"Font-size": "12px ",
"Font-weight": "normal ",
Color: "# 06c ",
"Line-height": "22px"
});
});
$ (". Tabbox Div"). Each (function (){
Certificate (this).css ({
Width: $. FN. tabbox. defaults. Width + "PX ",
Height: ($. FN. tabbox. defaults. Height-30) + "PX ",
Display: "NONE ",
Position: "absolute ",
Top: "30px"
});
});
$ (". Tabbox h2.curtab" detail .css ({
Background: "URL (" + $. FN. tabbox. defaults. basepath + "tabcurtab.gif) top center no-repeat ",
"Font-weight": "Bolder"
});
$ (". Tabbox h2.curtab + Div" ).css ({
Display: "Block"
});
};

We can see that this function is all code for setting styles. (I also experienced the pleasure of setting CSS with JQ. I still remember the era of E. style. backgroud ~), This function ensures that the currently activated tags and corresponding information are displayed. In addition, you can change the current activation tag by capturing the Click Event of the tab, and then render it again.Copy codeThe Code is as follows: $ (". tabbox H2"). Click (function (){
$ (". Tabbox H2"). removeclass ("curtab ");
$ (This). addclass ("curtab ");
$. FN. tabbox. Render ();
});

A bit of thought after writing:

1. I am not familiar with plug-in customization optionsCopy codeThe Code is as follows: // build main options before element Iteration
VaR opts = $. Extend ({}, $. FN. tabbox. defaults, options );
// Iterate and reformat each matched element
Return this. Each (function (){
$ This = $ (this );
// Build element specific options
VaR o = $. Meta? $. Extend ({}, opts, $ this. Data (): opts;

This is from Mike alsup.Article. According to his statement, it seems that the options of the entire plug-in can be customized, and the options of a specific element can be defined. But I tried it and it seems that it is not ~. Didn't I understand what he said?

2. Currently, tabs capture click events. I Want To enhance it. You can define whether to capture click or Mouseover. Yes, you can write two event processing functions. But how can we determine which processing to call through configuration?ProgramWhat about it?
Package download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.