小程序css实现容器内 数据滚动 无缝衔接 点击暂停

bash 复制代码
<view class="gundongBox">
				<!-- 滚动展示信息的模块 -->
				<image class="imgWid" :src="imgurl+'gundong.png'" mode="widthFix"></image>
				<view class="gundongView">
					<view class="container">
						<view class="scroll-container"
							:style="{ animationPlayState: autoScroll ? 'running' : 'paused',animationDuration:list.length>0?list.length +'s':0+'s' }" @touchstart="pauseScroll"
							@touchend="resumeScroll">
							<view v-for="(item, index) in list" :key="index" class="item">
								{{ item }}
							</view>
							<!-- 复制一份实现无缝循环 -->
							<view v-for="(item, index) in list" :key="'copy-'+index" class="item">
								{{ item }}
							</view>
						</view>
					</view>
				</view>
			</view>
bash 复制代码
<script>
	export default {
		components: {},
		data() {
			return {
				list: ["a", "b", "c"],
				autoScroll: true,
				resumeTimer: null
			}
		},
		onLoad(options) {
			// console.log("接收的参数",options)
		},
		methods: {
			pauseScroll() {
				this.autoScroll = false;
				clearTimeout(this.resumeTimer);
			},
			resumeScroll() {
				this.resumeTimer = setTimeout(() => {
					this.autoScroll = true;
				}, 2000);
			}
		}
	}
</script>
bash 复制代码
<style>
.gundongView {
		height: 500rpx;
		overflow: hidden;
	}
.container {
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	}
	
	.scroll-container {
	  /* height: 300px; */
	  width: 80%;
	  overflow: hidden;
	  position: relative;
	  border: 1px solid #eee;
	  animation: scroll 20s linear infinite; 
	  /* 默认执行20s */
	}
	
	@keyframes scroll {
	  0% {
	    transform: translateY(0);
	  }
	  100% {
	    transform: translateY(-50%);
	  }
	}
	
	.item {
	  padding: 20rpx;
	  border-bottom: 1px solid #f0f0f0;
	}
</style>
相关推荐
你的人类朋友22 分钟前
什么是API签名?
前端·后端·安全
会豪2 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子2 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶2 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子2 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_3 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_23333 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin3 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js
遂心_3 小时前
深入理解 React Hook:useEffect 完全指南
前端·javascript·react.js
Moonbit4 小时前
MoonBit 正式加入 WebAssembly Component Model 官方文档 !
前端·后端·编程语言