vue3實現(xiàn)無縫滾動列表效果(大屏數(shù)據(jù)輪播場景)
實現(xiàn)思路
vue3目前可以通過第三方組件來實現(xiàn)這個需求。
下面介紹一下這個第三方滾動組件--vue3-scroll-seamless
vue3-scroll-seamless
是一個用于 Vue 3 的插件,用于實現(xiàn)無縫滾動的組件。它可以讓內(nèi)容在水平或垂直方向上無縫滾動,適用于展示輪播圖、新聞滾動、圖片展示等場景。
主要特性和用法
無縫滾動:在內(nèi)容超出容器寬度或高度時,可以實現(xiàn)自動無縫滾動,形成連續(xù)的視覺效果。
多種配置選項:提供了多種配置選項來控制滾動的速度、方向、內(nèi)容顯示方式等。
響應式支持:支持響應式設計,可以根據(jù)父容器的大小自動調(diào)整內(nèi)容的顯示和滾動效果。
靈活的內(nèi)容布局:內(nèi)容可以是任意的 Vue 組件或 HTML 元素,可以自定義每一項的樣式和內(nèi)容。
事件和方法:支持一些事件回調(diào)和方法,例如滾動到指定位置、開始、暫停、重新開始滾動等。
官網(wǎng)地址:vue3-scroll-seamless | vue3-scroll-seamless (xiaofulzm.github.io)
建議去參考網(wǎng)文檔使用。
無縫滾動列表實現(xiàn)
安裝依賴
npm install vue3-scroll-seamless --save
main.js/ts導入
// 導入Vue3 Scroll Seamless組件 import {vue3ScrollSeamless} from "vue3-scroll-seamless"; // 注冊 Vue3 Scroll Seamless 組件 app.component('vue3ScrollSeamless',vue3ScrollSeamless) // 掛載Vue應用 app.mount('#app')
實現(xiàn)代碼示例
以上代碼用到了element-plus的el-row和el-col組件
<script lang="ts" setup> import { reactive } from "vue"; import { vue3ScrollSeamless } from "vue3-scroll-seamless"; const list = reactive([ { trainNumber: 'G1234', destination: '北京南', departureTime: '09:00', status: '準點' }, { trainNumber: 'G5678', destination: '上海虹橋', departureTime: '09:15', status: '準點' }, { trainNumber: 'D4321', destination: '廣州南', departureTime: '09:30', status: '晚點' }, { trainNumber: 'G8765', destination: '成都東', departureTime: '09:45', status: '準點' }, { trainNumber: 'G9876', destination: '西安北', departureTime: '10:00', status: '準點' }, { trainNumber: 'D6543', destination: '深圳北', departureTime: '10:15', status: '準點' }, { trainNumber: 'G2345', destination: '重慶北', departureTime: '10:30', status: '晚點' }, { trainNumber: 'G1111', destination: '天津西', departureTime: '10:45', status: '準點' }, { trainNumber: 'G2222', destination: '南京南', departureTime: '11:00', status: '晚點' }, { trainNumber: 'D3333', destination: '杭州東', departureTime: '11:15', status: '準點' }, { trainNumber: 'G4444', destination: '武漢', departureTime: '11:30', status: '準點' }, { trainNumber: 'G5555', destination: '濟南西', departureTime: '11:45', status: '準點' }, { trainNumber: 'D6666', destination: '長沙南', departureTime: '12:00', status: '晚點' }, { trainNumber: 'G7777', destination: '南昌西', departureTime: '12:15', status: '準點' }, { trainNumber: 'G8888', destination: '沈陽北', departureTime: '12:30', status: '準點' }, { trainNumber: 'D9999', destination: '福州南', departureTime: '12:45', status: '準點' }, { trainNumber: 'G1010', destination: '哈爾濱西', departureTime: '13:00', status: '晚點' } ]); const classOptions = reactive({ step: 0.5,//滾動速度值越大越快,但是值太小會卡頓 limitMoveNum: list.length,//無縫滾動列表元素的長度,一般設置為列表的長度 direction: 1,//方向: 0 往下 1 往上 2 向左 3 向右。 }); </script> <template> <div class="demo"> <div class="title-container"> <div class="title">車次信息展示列表</div> </div> <div class="table-header"> <div class="header"> <el-row> <el-col :span="6" class="center"> <div>車次</div> </el-col> <el-col :span="6" class="center"> <div>目的地</div> </el-col> <el-col :span="6" class="center"> <div>發(fā)車時間</div> </el-col> <el-col :span="6" class="center"> <div>狀態(tài)</div> </el-col> </el-row> </div> </div> <vue3ScrollSeamless class="scroll-wrap border text-color" :classOptions="classOptions" :dataList="list"> <div v-if="list.length > 0"> <el-row v-for="(item, i) of list" :key="i"> <el-col :span="6" class="center"> <div>{{ item.trainNumber }}</div> </el-col> <el-col :span="6" class="center"> <div>{{ item.destination }}</div> </el-col> <el-col :span="6" class="center"> <div style="width: 30px;">{{ item.departureTime }}</div> </el-col> <el-col :span="6" class="center"> <div style="width: 30px;">{{ item.status }}</div> </el-col> </el-row> </div> <div v-if="list.length == 0" style="width: 100%;height: 100px;display: flex;justify-content: center;align-items: center;color: white;font-size: 18px;"> 暫無預測記錄</div> </vue3ScrollSeamless> </div> </template> <style scoped> .title-container { display: flex; align-items: center; justify-content: center; height: 30px; margin-bottom: 20px; } .title { font-size: 19px; } .demo { width: 100%; height: 100%; } .scroll-wrap { width: 100%; height: 300px; margin: 0 auto; overflow: hidden; background-color: rgb(0, 5, 38, 0.5); font-size: 15px; } .table-header { font-family: Arial, sans-serif; height: 40px; display: flex; align-items: center; border: 1px solid rgb(13, 162, 221); background-color: rgba(3, 137, 174, 0.5); } .header { width: 100%; font-size: 16px; } .border { border: 1px solid rgb(13, 162, 221); } .center { display: flex; align-items: center; justify-content: center; } .text-color { color: rgb(128, 250, 124); } </style>
效果展示
到此這篇關于vue3實現(xiàn)無縫滾動列表效果(大屏數(shù)據(jù)輪播場景)的文章就介紹到這了,更多相關vue3無縫滾動列表內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
element-plus中el-table點擊單行修改背景色方法
這篇文章主要給大家介紹了關于element-plus中el-table點擊單行修改背景色的相關資料,這是產(chǎn)品新加了的一個需求,分享給同樣遇到這個需求的朋友,需要的朋友可以參考下2023-07-07在Vue3.x中實現(xiàn)類似React.lazy效果的方法詳解
React 的 React.lazy 功能為組件懶加載提供了原生支持,允許開發(fā)者將組件渲染推遲到實際需要時再進行,雖然 Vue3.x 沒有一個直接對應的 lazy 函數(shù),但我們可以通過動態(tài)導入和 defineAsyncComponent 方法來實現(xiàn)類似的效果,需要的朋友可以參考下2024-03-03vue中使用vue-print.js實現(xiàn)多頁打印
這篇文章主要介紹了vue中使用vue-print.js實現(xiàn)多頁打印,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03用Axios Element實現(xiàn)全局的請求loading的方法
本篇文章主要介紹了用Axios Element實現(xiàn)全局的請求loading的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03