相册图片切换效果-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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!