小程序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>
相关推荐
小磊哥er3 分钟前
【前端工程化】前端工作中的业务规范有哪些
前端
ᥬ 小月亮14 分钟前
webpack基础
前端·webpack
YongGit33 分钟前
探索 AI + MCP 渲染前端 UI
前端·后端·node.js
慧一居士1 小时前
<script setup>中的setup作用以及和不带的区别对比
前端
RainbowSea2 小时前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
读书点滴2 小时前
笨方法学python -练习14
java·前端·python
Mintopia2 小时前
四叉树:二维空间的 “智能分区管理员”
前端·javascript·计算机图形学
Mintopia2 小时前
Three.js 深度冲突:当像素在 Z 轴上玩起 "挤地铁" 游戏
前端·javascript·three.js
Penk是个码农2 小时前
web前端面试-- MVC、MVP、MVVM 架构模式对比
前端·面试·mvc
MrSkye2 小时前
🔥JavaScript 入门必知:代码如何运行、变量提升与 let/const🔥
前端·javascript·面试