<ul> <li v-for="list in slideList"> <img :src="list.image" :alt="list.desc"> </li> </ul>
<div class="carousel-wrap" id="carousel">
// 轮播图列表
<transition-group tag="ul" class='slide-ul' name="list">
<li v-for="(list,index) in slideList" :key="index" v-show="index===currentIndex" @mouseenter="stop" @mouseleave="go">
<a :href="list.clickUrl" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<img :src="list.image" :alt="list.desc">
</a>
</li>
</transition-group>
// 轮播图位置指示
<div class="carousel-items">
<span v-for="(item,index) in slideList.length" :class="{'active':index===currentIndex}" @mouseover="change(index)"></span>
</div>
</div>
data: {
slideList: [
{
"clickUrl": "#",
"desc": "nhwc",
"image": "http://dummyimage.com/1745x492/f1d65b"
},
{
"clickUrl": "#",
"desc": "hxrj",
"image": "http://dummyimage.com/1745x492/40b7ea"
},
{
"clickUrl": "#",
"desc": "rsdh",
"image": "http://dummyimage.com/1745x492/e3c933"
}
],
currentIndex: 0,
timer: ''
},
<li v-for="(list,index) in slideList" :key="index"> <a :href="list.clickUrl" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img :src="list.image" :alt="list.desc"> </a> </li>
<li v-for="(list,index) in slideList" :key="index" v-show="index===currentIndex" @mouseenter="stop" @mouseleave="go"> <a :href="list.clickUrl" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <img :src="list.image" :alt="list.desc"> </a> </li>
//在下个tick执行等待图片加载完成后再
this.$nextTick(() => {
this.timer = setInterval(() => {
this.autoPlay()
},4000)
}),
go() {
this.timer = setInterval(() => {
this.autoPlay()
},4000)
},
stop() {
clearInterval(this.timer)
this.timer = null
},
change(index) {
this.currentIndex = index
},
autoPlay() {
this.currentIndex++
if (this.currentIndex > this.slideList.length - 1) {
this.currentIndex = 0
}
}
<div class="carousel-items">
<span v-for="(item,index) in slideList.length" :class="{'active':index===currentIndex}" @mouseover="change(index)"></span>
</div>
.carousel-wrap {
position: relative;
height: 453px;
width: 100%;
overflow: hidden;
// 删除
background-color: #fff;
}
.slide-ul {
width: 100%;
height: 100%;
li {
position: absolute;
width: 100%;
height: 100%;
img {
width: 100%;
height: 100%;
}
}
}
.carousel-items {
position: absolute;
z-index: 10;
top: 380px;
width: 100%;
margin: 0 auto;
text-align: center;
font-size: 0;
span {
display: inline-block;
height: 6px;
width: 30px;
margin: 0 3px;
background-color: #b2b2b2;
cursor: pointer;
}
.active {
background-color: $btn-color;
}
}
.list-enter-active {
transition: all 1s ease;
transform: translateX(0)
}
.list-leave-active {
transition: all 1s ease;
transform: translateX(-100%)
}
.list-enter {
transform: translateX(100%)
}
.list-leave {
transform: translateX(0)
}
new Vue({
el: '#carousel',
data: {
slideList: [
{
"clickUrl": "#",
"desc": "nhwc",
"image": "http://dummyimage.com/1745x492/f1d65b"
},
{
"clickUrl": "#",
"desc": "hxrj",
"image": "http://dummyimage.com/1745x492/40b7ea"
},
{
"clickUrl": "#",
"desc": "rsdh",
"image": "http://dummyimage.com/1745x492/e3c933"
}
],
currentIndex: 0,
timer: ''
},
methods: {
this.$nextTick(() => {
this.timer = setInterval(() => {
this.autoPlay()
},4000)
})
go() {
this.timer = setInterval(() => {
this.autoPlay()
},4000)
},
stop() {
clearInterval(this.timer)
this.timer = null
},
change(index) {
this.currentIndex = index
},
autoPlay() {
this.currentIndex++
if (this.currentIndex > this.slideList.length - 1) {
this.currentIndex = 0
}
}
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有