Rumah > Soal Jawab > teks badan
Dimainkan dalam gelung
Ini bahagian data
data() {
return {
prizeList: [
{ name: 0 },
{ name: 1 },
{ name: 2 },
{ name: 3 },
{ name: 4 }
]
}
}
Ini adalah kod semasa saya, ia hanya boleh mengitar dan bertukar tanpa kesan animasi
setInterval(async () => {
let first = this.prizeList.splice(0, 1)
this.prizeList.push(...first)
}
世界只因有你2017-05-19 10:45:20
Anda boleh mengubah fikiran anda dan menggunakan peralihan untuk mencapainya
<p class="scroll-wrap">
<ul class="scroll-content" :style="{ top }">
<li v-for="item in prizeList">{{item.name}}</li >
</ul>
</p>
export default {
data () {
return {
prizeList: [
{ name: 0 },
{ name: 1 },
{ name: 2 },
{ name: 3 },
{ name: 4 }
],
activeIndex: 0
}
},
computed: {
top() {
return - this.activeIndex * 50 + 'px';
}
},
mounted() {
setInterval(_ => {
if(this.activeIndex < this.prizeList.length) {
this.activeIndex += 1;
} else {
this.activeIndex = 0;
}
}, 1000);
}
};
.scroll-wrap{
width: 200px;
height: 50px;
border: 1px solid blue;
overflow: hidden;
}
.scroll-content{
position: relative;
transition: top 0.5s;
li{
line-height: 50px;
text-align: center;
}
}
Kesan
怪我咯2017-05-19 10:45:20
dokumentasi rasmi vue
Perpustakaan kesan animasi
Sangat mudah digunakan:
import 'animate'
<transition
name="custom-classes-transition"
enter-active-class="animated bounceIn" //animate 提供的动画效果
leave-active-class="animated bounceOutRight"
>
... //要使用动画效果的内容
</transition>