利用jquery eq()属性实现Tab标签的切换效果
发布时间:2023年12月22日
利用jquery eq()属性实现Tab标签的切换效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Tab标签的切换效果</title>
<style>
.tab {
margin: 200px;
}
.tab-bay {
overflow: hidden;
margin: 0;
padding: 0;
}
ul li {
list-style: none;
float: left;
}
.tab-item {
padding: 0 20px;
height: 40px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
list-style: none;
font-size: 16px;
font-weight: 500;
color: #333333;
position: relative;
border: 1px solid #c3c9d3;
cursor: pointer;
margin-left: -1px;
}
.tab-item:hover {
color: #409eff;
}
.active {
background: #409eff;
border-color: #409eff;
color: #FFFFFF;
}
.active:hover {
color: #FFFFFF;
}
.tab-item:first-child {
border-top-left-radius: 4px;
margin-left: 0;
}
.tab-item:last-child {
border-top-right-radius: 4px;
}
.conter-son {
background: rgb(255, 255, 255);
border: 1px solid #c3c9d3;
margin-top: -1px;
height: 100px;
line-height: 100px;
border-radius: 4px;
border-top-left-radius: 0px;
}
.conter-sona {
display: none;
text-align: center;
}
.conter-sonactive {
display: block;
}
</style>
</head>
<body>
<div class="tab">
<ul class="tab-bay">
<li class="tab-item active">tab1</li>
<li class="tab-item">tab2</li>
<li class="tab-item">tab3</li>
<li class="tab-item">tab4</li>
</ul>
<div class="conter-son">
<div class="conter-sona conter-sonactive">
<span>1</span>
</div>
<div class="conter-sona">
<span>2</span>
</div>
<div class="conter-sona">
<span>3</span>
</div>
<div class="conter-sona">
<span>4</span>
</div>
</div>
</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
<script>
$(function () {
$('.tab-bay .tab-item').click(function () {
$(this).addClass('active').siblings().removeClass('active');
$('.conter-son .conter-sona').eq($(this).index()).show().siblings().hide();
});
});
</script>
</body>
</html>
文章来源:https://blog.csdn.net/DHLSP15/article/details/135153712
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!