<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 去除默认样式 */
*{margin: 0;padding: 0;}
.clearfix:after,
.clearfix:before{content: '';display: table;}
.clearfix:after{clear: both;}
input{ border: none; outline: none; background-color: transparent; }
ul,ol{list-style-type: none;}
a{text-decoration: none;}
img{vertical-align: top;}
em,i{font-style: normal;}
#box{
width: 1000px;
height: 600px;
position: relative;
margin: 40px auto;
}
.list_box{
width: 1000px;
position: relative;
height: 600px;
overflow: hidden;
}
.list_box ul{
position: absolute;
top: 0;
left: 0;
display: flex;
}
.list_box ul li{
width: 1000px;
flex-shrink: 0;
height: 600px;
}
.list_box ul li img{
width: 100%;
height: 100%;
}
.list_box div{
position: absolute;
bottom: 0 ;
left: 0;
width: 100%;
text-align: center;
}
.list_box div span{
display: inline-block;
width: 10px;
height: 10px;
background-color: #fff;
border-radius: 50%;
margin: 5px 10px;
}
.list_box div .active{
background-color: red;
}
.left,
.right{
display: inline-block;
width: 50px;
height: 50px;
font-size: 40px;
color: #fff;
position: absolute;
top: 50%;
text-align: center;
}
.left{
left: 0px;
}
.right{
right: 0px;
}
</style>
</head>
<body>
<div id="box">
<div class="list_box">
<ul :style='{left: this.index * -1000 + "px"}'>
<li v-for="(i, $index) in arr" :key="$index"><img :src='i' ></li>
</ul>
<div>
<span v-for="(i, $index) in arr.length" :key="$index" :class="$index==index?'active':''" ></span>
</div>
<span class="left" @click='btna()'><</span>
<span class="right" @click='btnb()'>></span>
</div>
<!-- {{index * 1000}} -->
<!-- <div v-for="(i, $index) in arr" :key="$index" >{{i}}</div> -->
</div>
</body>
<script src="./vue.js"></script>
<script>
new Vue({
el:'#box',
data:{
arr:[
'./images/1.jpg',
'./images/2.jpg',
'./images/3.jpg',
'./images/4.jpg',
'./images/5.jpg',
'./images/6.jpg',
'./images/7.jpg',
'./images/8.jpg',
'./images/9.jpg',
'./images/10.jpg'
],
index : 0
},
methods:{
btna(){
console.log(this.index)
this.index--
if(this.index < 0){
this.index = this.arr.length - 1
}
},
btnb(){
console.log(this.index)
this.index++
if(this.index > this.arr.length - 1){
this.index = 0
}
}
}
})
</script>
</html>
vue实现轮播图
最新推荐文章于 2023-09-03 08:30:00 发布