<!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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/css/swiper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/js/swiper.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
<style>
*{
margin: 0;padding: 0;
}
ul{
overflow: hidden;
}
li,ul{
list-style: none;
}
li{
float: left;
width: 33%;
height: 50px;
line-height: 50px;
text-align: center;
}
.active{
color: red;
}
.swiper-container{
height: calc(100vh - 50px);
}
.swiper-slide{
overflow-y: scroll;
}
</style>
</head>
<body>
<ul>
<li class="active">首頁</li>
<li>發現</li>
<li>用戶</li>
</ul>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" style="background: red">
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
<p style="height:50px">1</p>
</div>
<div class="swiper-slide" style="background: yellow">
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
<p style="height:50px">2</p>
</div>
<div class="swiper-slide" style="background: pink">
<p style="height:50px">3</p>
<p style="height:50px">3</p>
<p style="height:50px">3</p>
</div>
</div>
</div>
<script>
$('li').each(function(e) {
var index = $(this).index();
$(this).click(function() {
$(this).addClass('active').siblings().removeClass('active')
mySwiper.slideTo(index);
})
})
var mySwiper = new Swiper ('.swiper-container', {
loop: false, // 循環模式選項
on: {
slideChange: function () {
$('li').eq(this.activeIndex).addClass('active').siblings().removeClass('active')
},
}
})
</script>
</body>
</html>