自动轮播图片5张每次展示三张

动态 未结 0 105
小小草
小小草 LV1 2023年9月23日 23:40 发表
以下是一个自动轮播图片,每次展示三张的示例代码: HTML部分: ```
  • {{ item }}
``` CSS部分: ``` .slider { width: 600px; height: 400px; overflow: hidden; } .slider ul { list-style: none; margin: 0; padding: 0; width: 300%; height: 100%; transition: transform 0.5s ease-in-out; } .slider li { float: left; width: 33.33%; height: 100%; text-align: center; font-size: 30px; line-height: 400px; background-color: #ccc; } ``` JavaScript部分: ``` new Vue({ el: '#app', data: { picList: ['pic1', 'pic2', 'pic3', 'pic4', 'pic5'], curList: [], curIndex: 0, timer: null }, mounted() { this.startAutoPlay(); }, methods: { startAutoPlay() { this.timer = setInterval(() => { this.next(); }, 2000); }, stopAutoPlay() { clearInterval(this.timer); }, previous() { if (this.curIndex > 0) { this.curIndex--; } else { this.curIndex = this.picList.length - 3; } this.curList = this.picList.slice(this.curIndex, this.curIndex + 3); }, next() { if (this.curIndex < this.picList.length - 3) { this.curIndex++; } else { this.curIndex = 0; } this.curList = this.picList.slice(this.curIndex, this.curIndex + 3); } }, watch: { curIndex() { const slider = this.$el.querySelector('.slider ul'); slider.style.transform
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复