css实现滚屏展示效果

本文介绍了一种在前端开发中实现无缝滑动列表的方法,通过将前四条数据复制到列表末尾,避免了循环结束时的数据瞬变现象。利用CSS动画实现每20秒平滑滚动显示20条数据,每页显示四条。代码示例使用Vue.js框架。
摘要由CSDN通过智能技术生成

我这里是20条数据循环展示,页面同时能展示四条数据,一次循环20s

实现无缝滑动需要把前四条数据加到最后,否则会出现数据瞬变(因为循环结束会瞬间拉回,原来位置重新向下滑动),也就是有24条数据

不说废话,直接上代码

实现滑动功能的主要代码

@keyframes myMove {
	  0% {
	    transform: translateY(0);
	  }
	  100% {
	    transform: translateY(-500%);//我是按百分比设定高度,所以下滑的距离是5*height
	  }
	}
animation: myMove 20s linear infinite;
		animation-fill-mode: forwards;

 

 

整个组件代码

<template>
	<div style="width: 100%;height: 100%;">
		<div class="title">
			<div class="list-title">地区</div>
			<div class="list-title">用户名</div>
			<div class="list-title">回收物</div>
			<div class="list-title">回收量</div>
			<div class="list-title">时间</div>
		</div>
		<div class="infos" >	
				<ul id="scroll-data">	
					<!-- <li class="info">
							<div class="list-info">小区</div>
							<div class="list-info">小区</div>
							<div class="list-info">小区</div>
							<div class="list-info">小区</div>
							<div class="list-info">小区1</div>
					</li> -->
		
				</ul>
				
		</div>
	</div>
</template>

<script>
	export default {
		name: 'scroll',
		props:['scrolldata'],
		data() {
			return {
				

			}
		},
		methods: {
			
		},
		watch:{
			scrolldata(newval,oldval){
				var cent = document.getElementById("scroll-data");
				cent.innerHTML=''
				if(newval.length!==0){
					for(var i = 0; i < newval.length; i++) {
						cent.innerHTML += "<li class='info'>"+ 
									"<div  class='list-info'>" + newval[i].comminName + "</div>"+
									"<div class='list-info'>" + newval[i].userName + "</div>" +
									"<div class='list-info'>" + newval[i].garbageTypeName + "</div>" +
									"<div class='list-info'>" + newval[i].garbageNumber + "</div>" +
									"<div class='list-info'>" + newval[i].recycleTime + "</div>" +
									"</li>";
					}
					for(var i = 0; i < 4; i++) {
						cent.innerHTML += "<li class='info'>"+ 
									"<div  class='list-info'>" + newval[i].comminName + "</div>"+
									"<div class='list-info'>" + newval[i].userName + "</div>" +
									"<div class='list-info'>" + newval[i].garbageTypeName + "</div>" +
									"<div class='list-info'>" + newval[i].garbageNumber + "</div>" +
									"<div class='list-info'>" + newval[i].recycleTime + "</div>" +
									"</li>";
					}
				}
			}
		}
	}
</script>

<style>
	.title{
		width: 100%;
		height: 20%;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
	}
	.list-title{
		width:20%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 20px;
		font-weight: 700;
		color: #FFFFFF;
	}
	.infos{
		width: 100%;
		height: 80%;
		overflow: hidden;
		text-align: center;
	}
	
	@keyframes myMove {
	  0% {
	    transform: translateY(0);
	  }
	  100% {
	    transform: translateY(-500%);
	  }
	}
	
	.infos>ul{
		animation: myMove 20s linear infinite;
		animation-fill-mode: forwards;
		width: 100%;
		height: 100%;
		list-style: none;
		padding: 0;
		margin: 0;
	}
	.infos>ul>li{
		width: 100%;
		height: 25%;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}
	
	.list-info{
		width:20%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值