87,996
社区成员
发帖
与我相关
我的任务
分享<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>轮播图切换效果</title>
<style type="text/css">
.banner {
position: relative;
}
.bannerImg {
position: relative;
height: 360px;
}
.bannerImg span {
/* 设置图片定位 */
position: absolute;
top: 0;
left: 0;
}
.bannerBtn {
width: 200px;
position: absolute;
left: 30%;
bottom: -20px;
text-align: center;
}
.bannerBtn li {
list-style: none;
border-radius: 50%;
float: left;
}
.bannerBtn li a {
/* 设置按钮样式 */
display: block;
width: 20px;
height: 20px;
border-radius: 50%;
margin: 5px;
color: #160303;
font-weight: bolder;
text-decoration: none;
}
</style>
<script src="js/vue.js"></script>
</head>
<body>
<div id="box">
<div class="banner">
<!--切换的图片-->
<div class="bannerImg">
<span v-for="(v,i) in banners" :key="i">
<img width="700" :src="banners[currentIndex].imgSrc" alt="">
</span>
</div>
<!--切换的小按钮-->
<ul class="bannerBtn">
<li v-for="num in 3">
<a href="javascript:;" class="aBtn" @click="change(num)">{{num}}</a>
</li>
</ul>
</div>
</div>
<script type="text/javascript">
//创建根实例
var vm = new Vue({
el: '#box',
data(){
return{
banners:[
{id:1,imgSrc:"img/ad1.png"},
{id:2,imgSrc:"img/ad2.png"},
{id:3,imgSrc:"img/ad3.png"},
],
currentIndex:0
}
},
methods:{
change(){
if (this.currentIndex == 3){
this.currentIndex = 0;
}
if (this.currentIndex == 0){
this.currentIndex = 1;
}
}
}
});
</script>
</body>
</html>