Home > Web Front-end > JS Tutorial > body text

Code to achieve label switching effect in jquery_jquery

WBOY
Release: 2016-05-16 18:10:01
Original
1203 people have browsed it

Core code:

Copy code The code is as follows:

$("ul > li") .hover(tab);

function tab() {
$(this).addClass("ll").siblings().removeClass("ll");
var tab = $ (this).attr("title");
$("#" tab).show().siblings().hide();
};

li中And the title must be consistent with the id in the div!
Complete code
Copy code The code is as follows:






  • 1< ;/li>
  • 2

  • 3



11111





Simple jQuery tab page Simple Tabs w (use CSS and JQuery)
I know there are many tutorials on how to create tabs using CSS and JQuery, but I decided to create my own tabs myself. Of course I don't know if the technique is the same, but I hope this tutorial is easy to follow and even easy for a beginner to follow.

Original text: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/

For those students who are not very familiar with JQuery, please read them Check out the official website for a general overview, and you can further explore these, these, and many more tutorials on JQuery.
Step1. Wireframe – HTML & CSS
Wireframe: a visual representation of the structure of a web page

Wireframe: a visual representation of the arrangement of a web page

Use an unordered list (ul) to render your tabs, and then place a container (div) of type "tab_container" below it. Remember that each list item (tab) has an attribute value of "href" that matches the ID name of the ".tab_content" div. This is a very important step! Because we use JQuery to implement the action (switching tabs) and rely on it. Please remember that I am using the generic name "tab1" to make it easier for you to understand. In fact, you must use keywords, which are more semantic and better for your SEO (search engine optimization).

HTML
Copy code The code is as follows:

If you have tried to create tabs through CSS before, you may have been frustrated by the problem of correctly aligning the tab borders. Here are some common problems that most friends encounter.

tab_bug

Here I come up with a solution to deal with this annoying problem. Please take a look at the image below and then take a look at the CSS, as well as the helper comments next to it, for a better understanding.

tab_fix

Tabs CSS
Copy code The code is as follows:

ul.tabs {
margin: 0;
padding: 0;
float: left;
list-style: none;
height: 32px; /*–Set height of tabs–*/
border-bottom: 1px solid #999;
border-left: 1px solid #999;
width: 100%;
}
ul.tabs li {
float: left;
margin: 0;
padding: 0;
height: 31px; /*–Subtract 1px from the height of the unordered list–*/
line-height: 31px; /*–Vertically aligns the text within the tab–*/
border: 1px solid #999;
border-left: none;
margin-bottom: -1px; /*–Pull the list item down 1px–*/
overflow: hidden;
position: relative;
background: #e0e0e0;
}
ul.tabs li a {
text-decoration: none;
color: #000;
display: block;
font-size: 1.2em;
padding: 0 20px;
border: 1px solid #fff; /*–Gives the bevel look with a 1px white border inside the list item–*/
outline: none;
}
ul.tabs li a:hover {
background: #ccc;
}
html ul.tabs li.active, html ul.tabs li.active a:hover { /*–Makes sure that the active tab does not listen to the hover properties–*/
background: #fff;
border- bottom: 1px solid #fff; /*–Makes the active tab look like it's connected with its content—*/
}


Tab Content CSS
Copy code The code is as follows:

.tab_container {
border: 1px solid #999;
border-top : none;
overflow: hidden;
clear: both;
float: left; width: 100%;
background: #fff;
}
.tab_content {
padding: 20px;
font-size: 1.2em;
}

Step2. Make the label move – JQuery
For those who are not very familiar with JQuery, please read them The official website for a general overview

The following script contains comments explaining which JQuery action is being executed.
Copy code The code is as follows:

$(document).ready(function() {

//When page loads…
$(“.tab_content”).hide(); //Hide all content
$(“ul.tabs li:first”).addClass(“active ”).show(); //Activate first tab
$(“.tab_content:first”).show(); //Show first tab content

//On Click Event
$ (“ul.tabs li”).click(function() {

$(“ul.tabs li”).removeClass(“active”); //Remove any “active” class
$ (this).addClass(“active”); //Add “active” class to selected tab
$(“.tab_content”).hide(); //Hide all tab content

var activeTab = $(this).find(“a”).attr(“href”); //Find the href attribute value to identify the active tab content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});

View Demo

Finally

Finally you have it, a beautiful and simple tag function made with CSS and JQuery. If you have any questions, comments, or suggestions please feel free to let me know!
Full demo code:

Copy the code The code is as follows:

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



Simple Tabs with CSS & jQuery






Simple Tabs w/ CSS & jQuery





Gallery



www.DesignBombs.com


Saw polecat than took bankrupt good hillbilly stew, crazy, fancy and hillbilly heap rodeo, pappy. Thar range saw me him sherrif nothin' shiney dirt, pigs sheep city-slickers everlastin' shotgun driveway. Promenade catfight fart fiddle jiggly gonna tarnation, fence, what quarrel dirty, if. Pot grandma crop kinfolk jezebel diesel coonskin hoosegow wirey fixin' shack good roped in. Reckon stew tax-collectors, grandpa tobaccee hayseed good wash tired caboodle burnin' landlord.


Smokin' driveway wrestlin' go darn truck moonshine wirey cow grandpa saw, coonskin bull, java, huntin'.


Stinky yonder pigs in, rustle kinfolk gonna marshal sittin' wagon, grandpa. Ya them firewood buffalo, tobaccee cabin.




Submit



www.DesignBombs.com


Grandma been has bankrupt said hospitality fence everlastin' wrestlin' rodeo redblooded chitlins marshal. Boobtube soap her hootch lordy cow, rattler.


Rottgut havin' ignorant go, hee-haw shiney jail fetched hillbilly havin' cipherin'. Bacon no cowpoke tobaccee horse water rightly trailer tools git hillbilly.


Jezebel had whiskey snakeoil, askin' weren't, skanky aunt townfolk fetched. Fit tractor, them broke askin', them havin' rattler fell heffer, been tax-collectors buffalo. Quarrel confounded fence wagon trailer, moonshine wuz, city-slickers fixin' cow.




Resources



www.DesignBombs.com


Dirt tools thar, pot buffalo put jehosephat rent, ya pot promenade. Come pickled far greasy fightin', wirey, it poor yer, drive jig landlord. Rustle is been moonshine whomp hogtied. Stew, wirey stew cold uncle ails. Slap hoosegow road cooked, where gal pot, commencin' country. Weren't dogs backwoods, city-slickers me afford boxcar fat, dumb sittin' sittin' drive rustle slap, tornado. Fuss stinky knickers whomp ain't, city-slickers sherrif darn ignorant tobaccee round-up old buckshot that.


Deep-fried over shootin' a wagon cheatin' work cowpoke poor, wuz, whiskey got wirey that. Shot beer, broke kickin' havin' buckshot gritts. Drunk, em moonshine his commencin' country drunk chitlins stole. Fer tonic boxcar liar ass jug cousin simple, wuz showed yonder hee-haw drive is me. Horse country inbred wirey, skanky kinfolk. Rattler, sittin' darn skanky fence, shot huntin'.




연락처



www.DesignBombs.com


할머니는 환대 울타리 영원한 레슬링 로데오 붉은 피의 치틀린스 보안관이 파산했다고 말했습니다. Boobtube는 그녀의 멍청이 소, 딸랑이를 비누로 만듭니다.


Rottgut는 무지하게 가버렸어요, 희호 샤이니 감옥에서 촌놈을 데려와 암호를 해독했습니다. 베이컨 없음 Cowpoke 담배 말 물 올바르게 트레일러 도구 git Hillbilly.


이세벨은 위스키 뱀기름을 마셨는데, 그렇지 않냐고 묻자 동네 사람들이 천박한 이모를 데려왔습니다. 트랙터를 맞췄는데, 그들은 망가졌고, 덜거덕거리는 소리가 났고, 세금 징수원이었던 버팔로였습니다. 싸움은 울타리 왜건 트레일러, 밀주 wuz, 소를 고치는 도시 슬리커를 혼란스럽게 만들었습니다.





CSS 및 jQuery가 포함된 간단한 탭 다나카 소우 지음. 그의 웹 디자인 블로그를 확인해 보세요. 더 많은 튜토리얼을 보려면!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!