How to automatically switch tabs using jQuery

Source: Internet
Author: User

How to automatically switch tabs using jQuery

This article mainly introduces jQuery's automatic switch of tab labels. Examples of jQuery's skills in operating tab, involving addClass, siblings, and removeClass chain operations are analyzed. For more information, see

 

 

This document describes how to automatically switch tabs using jQuery. Share it with you for your reference. The specific implementation method is as follows:

 

The Code is as follows:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> automatic switch of tabs implemented by jQuery </title>
<Style type = "text/css">
*{
Margin: 0;
Padding: 0;
}
Dl {
Margin: 10px auto;
Width: 500px;
Line-height: 24px;
Border-left: 1px solid # dcdcdc;
}
Dt. active {
Border-bottom: 1px solid # fff;
Position: relative;
}
Dt {
Padding: 0 10px;
Float: left;
Border: 1px solid # dcdcdc;
Border-left: 0;
Cursor: pointer;
Margin-bottom:-1px;
}
Dd {
Clear: both;
Width: 100%;
Border-left: 0;
Border: 1px solid # dcdcdc;
Border-left: 0;
Display: none;
}
</Style>
</Head>
<Body>
<Dl>
<Dt> nav1 </dt>
<Dt> nav2 </dt>
<Dt> nav3 </dt>
& Lt; dd & gt; 1111111111111111111111 & lt;/dd & gt;
& Lt; dd & gt; 2222222222222222222222 & lt;/dd & gt;
& Lt; dd & gt; 3333333333333333333333 & lt;/dd & gt;
</Dl>
<Script type = "text/javascript" src = "/html/txdm_2/images/20101004/jquery-1.2.6.min.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ('Dt: first '). addClass ('active ');
$ ('Dd: first'mirror.css ('display', 'block ');
Autoroll ();
HookThumb ();
});
Var I =-1; // start with the I + 1 tab
Var offset = 2500; // rotation time
Var timer = null;
Function autoroll (){
N = $ ('dt'). length-1;
I ++;
If (I> n ){
I = 0;
}
Slide (I );
Timer = window. setTimeout (autoroll, offset );
}
Function slide (I ){
$ ('Dt '). eq (I). addClass ('active'). siblings (). removeClass ('active ');
Certificate ('dd'0000.eq(i0000.css('display', 'block'0000.siblings('dd'0000.css ('display', 'None ');
}
Function hookThumb (){
$ ('Dt'). hover (
Function (){
If (timer ){
ClearTimeout (timer );
I = $ (this). prevAll (). length;
Slide (I );
}
},
Function (){

Timer = window. setTimeout (autoroll, offset );
This. blur ();
Return false;
}
);
}
</Script>
</Body>
</Html>

 

I hope this article will help you design javascript programs.

Related Article

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.