vue實(shí)現(xiàn)無縫滾動(dòng)的示例詳解
vue非組件實(shí)現(xiàn)列表的無縫滾動(dòng)問題(小編能力有限,如有更好方法還請(qǐng)大佬指點(diǎn)一二)
*原理:首先循環(huán)兩遍數(shù)組,當(dāng)容器滾去第一個(gè)數(shù)組高度的時(shí)候,第二個(gè)數(shù)組剛好填滿容器,這時(shí)候?qū)L去高度設(shè)置為0則可以實(shí)現(xiàn)無縫滾動(dòng)。
*簡易原理圖如下

話不多說直接上代碼:
1.采用js的方法實(shí)現(xiàn)
<template>
<div>
<div class="box">
<div v-for="item in 2" class="item-box" :style="{transform:'translate(0,'+scrollTop+'px)'}">
<div class="item" v-for="i in 9">{{i}}</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
scrollTop: 0,
}
},
onLoad() {
this.roll()
},
methods: {
roll() {
if (this.scrollTop == -300) {
this.scrollTop = 0
}
this.scrollTop -= 1;
setTimeout(() => {
this.roll()
}, 10)
},
}
}
</script>
<style>
.box {
width: 320px;
height: 300px;
background-color: pink;
overflow: hidden;
}
.box .item-box {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.box .item-box .item {
width: 29%;
height: 29%;
margin: 1%;
background-color: paleturquoise;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
}
</style>2.css動(dòng)畫實(shí)現(xiàn)
<template>
<div>
<div class="box">
<div v-for="item in 2" class="item-box">
<div class="item" v-for="i in 9">{{i}}</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {}
},
methods: {
}
}
</script>
<style>
.box {
width: 320px;
height: 300px;
background-color: pink;
overflow: hidden;
}
.box .item-box {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
animation: roll 5s linear infinite;
}
.box .item-box .item {
width: 29%;
height: 29%;
margin: 1%;
background-color: paleturquoise;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
}
@keyframes roll {
0% {
transform: translate(0, 0px);
}
20% {
transform: translate(0, -60px);
}
40% {
transform: translate(0, -120px);
}
60% {
transform: translate(0, -180px);
}
80% {
transform: translate(0, -240px);
}
100% {
transform: translate(0, -300px);
}
}
</style>到此這篇關(guān)于vue實(shí)現(xiàn)無縫滾動(dòng)的示例詳解的文章就介紹到這了,更多相關(guān)vue無縫滾動(dòng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue條件渲染列表渲染原理示例詳解
- antd vue表格可編輯單元格以及求和實(shí)現(xiàn)方式
- vue3實(shí)現(xiàn)無縫滾動(dòng)組件的示例代碼
- vue實(shí)現(xiàn)無縫滾動(dòng)手摸手教程
- vue實(shí)現(xiàn)消息向上無縫滾動(dòng)效果
- vue實(shí)現(xiàn)無限消息無縫滾動(dòng)
- vue實(shí)現(xiàn)簡單無縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表無縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表垂直無縫滾動(dòng)
- vue實(shí)現(xiàn)列表無縫滾動(dòng)
- el-table動(dòng)態(tài)渲染列、可編輯單元格、虛擬無縫滾動(dòng)的實(shí)現(xiàn)
相關(guān)文章
Vue子組件調(diào)用父組件的三種方法(附詳細(xì)代碼演示)
我們?cè)谑褂胿ue做前端代碼的時(shí)候,經(jīng)常出現(xiàn)父組件調(diào)用子組件的場景需求,這篇文章主要介紹了Vue子組件調(diào)用父組件的三種方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-07-07
vue mounted()函數(shù)中無法定義初始化樣式的原因分析
這篇文章主要介紹了vue mounted()函數(shù)中無法定義初始化樣式的原因分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
關(guān)于移動(dòng)端與大屏幕自適應(yīng)適配方案
這篇文章主要介紹了關(guān)于移動(dòng)端與大屏幕自適應(yīng)適配方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue3 ts打包失敗ts類型校驗(yàn)未通過導(dǎo)致打包失敗的解決方案
這篇文章主要介紹了vue3 ts打包失敗ts類型校驗(yàn)未通過導(dǎo)致打包失敗的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-06-06
Vue報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED解決方法
Vue項(xiàng)目啟動(dòng)時(shí)報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED,本文主要介紹了Vue報(bào)錯(cuò)ERR_OSSL_EVP_UNSUPPORTED解決方法,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08
uniapp?vue3中使用webview在微信小程序?qū)崿F(xiàn)雙向通訊功能
微信小程序的存在許多功能上的限制和約束,有些情況不得不去使用webview進(jìn)行開發(fā)實(shí)現(xiàn)需求,這篇文章主要給大家介紹了關(guān)于uniapp?vue3中使用webview在微信小程序?qū)崿F(xiàn)雙向通訊功能的相關(guān)資料,需要的朋友可以參考下2024-07-07

