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

話不多說(shuō)直接上代碼:
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)畫(huà)實(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)無(wú)縫滾動(dòng)的示例詳解的文章就介紹到這了,更多相關(guān)vue無(wú)縫滾動(dòng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue條件渲染列表渲染原理示例詳解
- antd vue表格可編輯單元格以及求和實(shí)現(xiàn)方式
- vue3實(shí)現(xiàn)無(wú)縫滾動(dòng)組件的示例代碼
- vue實(shí)現(xiàn)無(wú)縫滾動(dòng)手摸手教程
- vue實(shí)現(xiàn)消息向上無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)無(wú)限消息無(wú)縫滾動(dòng)
- vue實(shí)現(xiàn)簡(jiǎn)單無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)效果
- vue實(shí)現(xiàn)列表垂直無(wú)縫滾動(dòng)
- vue實(shí)現(xiàn)列表無(wú)縫滾動(dòng)
- el-table動(dòng)態(tài)渲染列、可編輯單元格、虛擬無(wú)縫滾動(dòng)的實(shí)現(xiàn)
相關(guān)文章
Vue監(jiān)聽(tīng)數(shù)據(jù)對(duì)象變化源碼
這篇文章主要為大家詳細(xì)介紹了Vue監(jiān)聽(tīng)數(shù)據(jù)對(duì)象變化的源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
vue獲取DOM元素并設(shè)置屬性的兩種實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇vue獲取DOM元素并設(shè)置屬性的兩種實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
Vue如何動(dòng)態(tài)給id設(shè)置style樣式
這篇文章主要介紹了Vue如何動(dòng)態(tài)給id設(shè)置style樣式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
使用electron-builder將項(xiàng)目打包成桌面程序的詳細(xì)教程
這篇文章主要介紹了使用electron-builder把web端的項(xiàng)目打包生成桌面程序,并可安裝程序,文中通過(guò)代碼示例和圖文結(jié)合的方式給大家介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2024-08-08
vue如何轉(zhuǎn)換時(shí)間格式為年月日時(shí)分秒和年月日(補(bǔ)零)
這篇文章主要介紹了vue如何轉(zhuǎn)換時(shí)間格式為年月日時(shí)分秒和年月日(補(bǔ)零),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04
Vue手動(dòng)埋點(diǎn)設(shè)計(jì)的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Vue手動(dòng)埋點(diǎn)設(shè)計(jì)的相關(guān)資料,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,需要的朋友可以參考下2022-03-03

