<!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>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.box {
width: 350px;
margin: 100px auto;
}
.title {
width: 350px;
height: 50px;
display: flex;
justify-content: space-around;
align-items: center;
}
.title h2.active {
color: red;
}
ul li {
width: 350px;
height: 350px;
text-align: center;
line-height: 350px;
font-size: 35px;
font-weight: bold;
display: none;
background: red;
}
ul li:first-child {
display: block;
}
ul li:nth-child(2) {
background: pink;
}
ul li:nth-child(3) {
background: skyblue;
}
</style>
</head>
<body>
<div class="box">
<div class="title">
<h2 class="active">标题1</h2>
<h2>标题2</h2>
<h2>标题3</h2>
</div>
<ul>
<li>tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
</div>
<script src="./jquery-1.8.3.min.js"></script>
<script>
$('.title h2').on('click', function () {
$(this).addClass('active').siblings().removeClass('active')
$('ul li').eq($(this).index()).show(300).siblings().hide(300)
})
</script>
</body>
</html>
tap栏切换
最新推荐文章于 2024-04-14 17:05:03 发布