遇到一個需求,一個列表,后端返回所有數據,前端進行滾動展示每頁三條數據,已經實現,代碼如下:
js部分
change () { document.querySelector('.el-table__body').classList.add('marquee_top') setTimeout(() => { this.tableData.push(this.tableData[0], this.tableData[1], this.tableData[2]) for (let i = 0; i < 3; i++) { this.tableData.shift() } document.querySelector('.el-table__body').classList.remove('marquee_top') }, 500) }, play () { setInterval(this.change, 3000) }, mounted () { this.play() }
css部分
.el-table__header-wrapper z-index 1000 position absolute .el-table__body-wrapper height 1.2rem margin-top .36rem z-index 100 .marquee_top transition all 0.5s margin-top -1.2rem