需求:在vue中v-for遍历图片列表依据index时定时给图片添加动画! 效果图: .VUE
<div class="a01_header">
<img
v-for="(items,index) in a01_header"
:key="index"
:class="selectIndex == index ? 'add_animation':''"
:src=items.img_url />
</div>
.JS
data: {
a01_header: [
{img_url: './img/01/imgs/a01.png'},
{img_url: './img/01/imgs/a02.png'},
{img_url: './img/01/imgs/a03.png'},
{img_url: './img/01/imgs/a04.png'},
{img_url: './img/01/imgs/a05.png'}
],
selectIndex:0
},
mounted: function() {
setInterval(() =>{
this.getMethon();
},2000)
},
getMethon(){
const { a01_header } = this;
let len = a01_header.length,
index = this.selectIndex;
if (index + 1 == len) {
this.selectIndex = 0
} else {
this.selectIndex = index + 1;
}
}
.CSS
.add_animation{
animation: scaleBtn 2s infinite ease-in-out;
}
@keyframes scaleBtn {
0% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
opacity: 1;
}
}
|