Custom jquery Tab Plug-in instance _jquery

Source: Internet
Author: User

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>jquery custom Tab Plugin </title>
<style>
Body, ul {padding:0; margin:0;}
Li {list-style:none;}
#tabs {zoom:1;}
#tab: After {content: ""; Display:block; Clear:both; }
#tabs li {float:left padding:10px; color: #FF8900; background: #FFF; cursor:pointer;}
#tabs. Active {background: #FF8900; color: #FFF;}
#tabContent {background: #FF8900; color: #FFF; padding:10px; clear:both;}
#tabContent div {display:none;}
#tabContent div.active {Display:block}
</style>

<body>
<ul id= "Tabs" >
<li data-tab= "Users" >Users</li>
<li data-tab= "Groups" >Groups</li>
</ul>

<div id= "Tabcontent" >
<div data-tab= "Users" >users content</div>
<div data-tab= "groups" >groups content</div>
</div>

<script src= "Http://code.jquery.com/jquery-1.9.1.min.js" ></script>
<script>
JQuery.fn.tabs = function (Control) {
var element = $ (this);
var control = $ (control);

Element.delegate (' Li ', ' click '), function () {
Traverse Tab Name
var tabname = $ (this). attr (' Data-tab ');

Trigger custom event when clicking on a tab
Element.trigger (' Change.tabs ', tabname);
});

Binding to custom events
Element.bind (' Change.tabs ', function (EV, tabname) {
Element.find (' Li '). Removeclass (' active ');
Element.find (' >[data-tab= ' + tabname + '] '). addclass (' active ');
});

Element.bind (' Change.tabs ', function (EV, tabname) {
Control.find (' >[data-tab] '). Removeclass (' active ');
Control.find (' >[data-tab= ' + tabname + '] '). addclass (' active ');
});

Activate the 1th tab
var firstName = element.find (' Li:first '). attr (' Data-tab ');
Element.trigger (' Change.tabs ', firstName);

return this;
};

JQuery (function ($) {
$ (' #tabs '). Tabs (' #tabContent ');

$ (' #tab '). Bind (' Change.tabs ', function (EV, tabname) {
Window.loaction.hash = tabname;
});

$ (window). bind (' Hashchange ', function () {
var tabname = Window.location.hash.slice (1);
$ (' #tabs '). Trigger (' Change.tabs ', tabname);
});
});
</script>
</body>

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.