?
?
<!-- Vue <transition-group> <table>数据滚动显示过渡案例-->
<template>
<div class="page">
<!--
Vue几乎支持所有原生js dom事件
html dom事件列表:https://www.runoob.com/jsref/dom-obj-event.html
-->
<table @mouseover="onMouseOverTable" @mouseout="onMouseOutTable">
<transition-group name="list-complete" tag="tbody">
<tr
v-for="(item,index) in items"
v-bind:key="item.txt"
class="list-complete-item"
v-if="index < 3"
>
<!-- 当前只显示 3 条数据 -->
<td>
{{ item.txt }}
</td>
<td>
{{ item.num }}
</td>
</tr>
</transition-group>
</table>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data() {
return {
items: [
{txt: 'apple', num: 1},
{txt: 'banana', num: 2},
{txt: 'tomatoes', num: 3},
{txt: 'strawberry', num: 4},
{txt: 'orange', num: 5},
{txt: 'grape', num: 6},
],
scrollName: null
}
},
computed: {},
mounted(){
this.setScrollAni();
},
methods: {
exchange(){
let self = this;
let firstEle = this.items[0];
this.items.splice(0, 1);
self.items.splice(self.items.length, 0, firstEle);
},
setScrollAni(){
let self = this;
if(self.scrollName){
clearInterval(self.scrollName)
}
self.scrollName = setInterval(function () {
self.exchange();
},1500)
},
onMouseOverTable(){
let self = this;
if(self.scrollName){
clearInterval(self.scrollName)
}
},
onMouseOutTable(){
this.setScrollAni()
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.list-complete-item {
transition: all 1s;
td {
border-top: 1px solid #ddd;
padding: 8px;
width: 150px;
}
}
.list-complete-leave-to
/* .list-complete-leave-active for below version 2. 1.8 */ {
opacity: 0;
transform: translateY(-30px);
}
.list-complete-enter
/* .list-complete-leave-active for below version 2. 1.8 */ {
opacity: 0;
transform: translateY(30px);
}
.list-complete-leave-active {
position: absolute;
}
</style>
|