相册图片切换效果-vue
效果:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>相册展示</title>
<style>
#app{
position: relative;
width: 500px;
}
img{
width: 500px;
}
#left{
position: absolute;
top: 150px;
left: 0;
}
#right{
position: absolute;
top: 150px;
right: 0;
}
button{
width: 30px;
height: 60px;
}
</style>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
<script src="../../node_modules/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<img :src="imgArr[showidx]">
<div id="btns">
<button id="left" @click="left()"><</button>
<button id="right" @click="right()">></button>
</div>
</div>
<script>
new Vue({
el:"#app",
data:{
showidx:0,
// imgUrl:'./images/1.jpg',
imgArr:[
'./images/1.jpg','./images/2.jpg','./images/3.jpg','./images/4.jpg'
]
},
methods:{
left(){
this.showidx--;
if(this.showidx <= -1){
this.showidx = 3;
}
// this.imgUrl = this.imgArr[this.showidx];
console.log(this.showidx)
},
right(){
this.showidx++;
if(this.showidx >= this.imgArr.length){
this.showidx = 0;
}
// this.imgUrl = this.imgArr[this.showidx];
console.log(this.showidx)
}
}
})
</script>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634681.html