⽤vue实现轮播图
轮播图有着许多实现⽅式,⾃⼰尝试⽤vue实现轮播图
上代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
background-color: black;
}
html{
height: 100%;
}
body{
height: 100%;
display: flex;
justify-content: center;
}
.app{
height: 100%;
width: 100%;
display: flex;
justify-content: center;
}
img{
width: 500px;
height: 300px;
}
li{
width: 500px;
height: 300px;
border: 5px solid white;
color: white;
position: absolute;
}
ul{
width: 510px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
}
.nav{
background-color: #c3c3c3;
color: white;
margin-left: 10px;
font-size: 20px;
border-radius: 50%;
js实现轮播图最简代码padding: 0 8px;
margin-bottom: 10px;
opacity: 0.5;
}
.active{
opacity: 1;
}
li div{
margin-top: -30px;
}
.image-enter-active {
transition: all 1.5s linear
}
.image-leave-active {
transition: all 1.5s linear;
}
.image-enter-to {
transform: translateX(0);
}
.image-enter {
transform: translateX(100%);
}
.image-leave {
transform: translateX(0);
}
.image-leave-to {
transform: translateX(-100%);
}
</style>
</head>
<body>
<div id="app">
<div  v-on:mouseover="stop()" v-on:mouseout="move()" class="app">
<transition-group tag="ul" name="image">
<li v-for="(items,index) in list" v-show="index===num" :key="index" >
<img :src="items" alt="">
<div>
<span v-for="(items,index) in data" class="nav" @click="change(index)" :class="{'active':index==num}">{{items}}</span>
</div>
</li>
</transition-group>
</div>
</div>
<script src="vue.js"></script>
<script>
new Vue({
el:'#app',
data(){
return{
data:['1','2','3'],
time:'',
num:0,
list:['timgsa.baidu/timg?image&quality=80&size=b9999_10000&sec=1534136662314&di=af7ec227db5e118a5626a94ab97026f3&img type=0&src=http%3A%2F%2Fc.hiphotos.baidu%2Fimage%2Fpic%2Fitem%2F4bed2e738bd4b31ccda81d7a8bd6277f9f2ff85f.jpg',
"ss3.baidu/-fo3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=4b22ec31ddc8a786a12a4c0e5708c9c7/5bafa40f4bfbfbedc55 97ab474f0f736aec31ffc.jpg",
"ss3.baidu/9fo3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=87d6daed02f41bd5c553eef461d881a0/f9198618367adab4b0 25268587d4b31c8601e47b.jpg"],
}
},
methods:{
play(){
this.time=setInterval(()=>{
this.num++;
if(this.num==3){
this.num=0
}
},2000)
},
change(i){
this.num=i
this.num=i
},
stop(){
clearInterval(this.time)            },
move(){
this.play();
}
},
created(){
this.play();
},
})
</script>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。