Jquery special effects (2)-tab, jquery special effects Tab

Source: Internet
Author: User

Jquery special effects (2)-tab, jquery special effects Tab

Recently, the company has a page that is easy to use and I wrote it. It feels pretty good and simple ~~~~

The following shows the dynamic effect:

 

I. Main Program

<! DOCTYPE html> 

 

 

Ii. CSS style

Preliminary Layout code:

*{ margin:0; padding:0}ul{    list-style: none;}.tab{    width: 300px;    margin: 0 auto;}.tab .tab_menu{    border: 1px solid #000000;    height: 30px;    width: 300px;    }.tab .tab_menu ul li{    float: left;    width: 99px;    text-align: center;    line-height: 30px;    border-right: 1px #333333 solid;}.tab .tab_menu ul li:last-child{    border-right:none;    width: 100px;}.tab .tab_menu ul li.on{    background: #999;}.tab .tab_box > div{    width: 300px;    height: 200px;    border: #333333 solid;    border-width: 0 1px 1px 1px;}

 

The layout of the code above is as follows:

However, we only need to display the content in a framework. Therefore, we can add some minor code assistance to the above Code ~~~~~~

Further layout style code:

* {Margin: 0; padding: 0} ul {list-style: none ;}. tab {width: 300px; margin: 0 auto ;}. tab. tab_menu {border: 1px solid #000000; height: 30px; width: 300px ;}. tab. tab_menu ul li {float: left; width: 99px; text-align: center; line-height: 30px; border-right: 1px #333333 solid ;}. tab. tab_menu ul li: last-child {border-right: none; width: 100px ;}. tab. tab_menu ul li. on {background: #999 ;}. tab. tab_box> div {width: 300px; height: 200px; border: #333333 solid; border-width: 0 1px 1px; display: none; // hide all three content frameworks. The first-child attribute below only shows the content of the first framework }. tab. tab_box> div: first-child {display: block ;}

The above program adds a display: none to the. tab. tab_box> div style, and only displays the content of the first frame through the first-child attribute ~~~~~~ In this way, we can see that the layout is consistent with the animation we just started to play, and the layout is complete ~~~~~~

 

Iii. Jquery code:

$ (Function () {$ (". tab_menu ul li "). click (function () {$ (this ). addClass ("on "). siblings (). removeClass ("on"); // switch the highlighted status of the selected button var index =$ (this ). index (); // obtain the index value of the pressed Button. Note that the index starts from 0 $ (". tab_box> div "). eq (index ). show (). siblings (). hide (); // when the button is selected, the corresponding content is displayed below, and unnecessary framework content is hidden });});

Well, I am also drunk when I see such a short Jquery code. After I write such a long piece of code in the layout, I just wrote five sentences to get it done ~~~ I have already written a comment clearly. For more information, see ~~~~

 

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.