html jQuery选项卡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html jQuery选项卡相关的知识,希望对你有一定的参考价值。
<!-- HTML -->
<div class="tabs-container">
<div class="flex tabs clearfix m0">
<div class="col col-12 sm-col-4 border active caps">
Tab 1
</div>
<div class="col col-12 sm-col-4 border caps">
Tab 2
</div>
<div class="col col-12 sm-col-4 border caps">
Tab 3
</div>
</div>
<!-- .tabs -->
<ul class="tab">
<li class="active">
<p> 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>
</li>
<!-- .tab 1 -->
<li>
<p> 2 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>
</li>
<!-- .tab 2 -->
<li>
<p> 3 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>
</li>
<!-- .tab 3 -->
</ul>
</div>
<!-- .tabs-container -->
<!-- jQuery Function -->
$(".tabs .col").click(function() {
if (!$(this).hasClass("active")) {
var tabNum = $(this).index();
var nthChild = tabNum + 1;
$(".tabs .active").removeClass("active");
$(this).addClass("active");
$(".tab li.active").removeClass("active");
$(".tab li:nth-child(" + nthChild + ")").addClass("active");
}
});
<!-- sass -->
.tabs-container {
background: $light-gray;
height: auto;
}
.tabs {
list-style-type: none;
padding: 0;
text-align: center;
margin: 0 0 5px 0;
.col {
@include inline-block;
vertical-align: middle;
background-color: $gray;
color: $white;
cursor: pointer;
font-size: 22px;
padding: 12px 10px 0px;
@include border-box;
position: relative;
height: auto;
min-height: 50px;
&.active {
background-color: $yellow;
}
}
}
ul.tab {
list-style-type: none;
margin: 0;
padding: 0;
& > li {
display: none;
padding: 0px;
&.active {
display: block;
}
}
.col {
height: 100%;
}
}
以上是关于html jQuery选项卡的主要内容,如果未能解决你的问题,请参考以下文章