最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)無縫滾動(dòng)的示例詳解

 更新時(shí)間:2023年09月06日 08:42:11   作者:Maidangchen  
這篇文章主要為大家詳細(xì)介紹了vue非組件如何實(shí)現(xiàn)列表的無縫滾動(dòng)效果,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

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)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

怀柔区| 和平区| 诏安县| 高要市| 关岭| 旬阳县| 洪雅县| 延寿县| 永兴县| 呼伦贝尔市| 友谊县| 民勤县| 甘孜| 长治市| 肃宁县| 淳安县| 丹江口市| 兴海县| 万荣县| 全州县| 会泽县| 雅安市| 儋州市| 静海县| 乐亭县| 钟山县| 绥宁县| 盐城市| 高阳县| 邛崃市| 利辛县| 长白| 江陵县| 卢湾区| 观塘区| 墨竹工卡县| 邹城市| 通辽市| 许昌市| 莎车县| 鹤山市|