小程序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>
相关推荐
整點薯條18 分钟前
Vue3+vite创建项目架构文件说明总结
前端·javascript·vue.js
掘金一周38 分钟前
想问问掘友们:AI 时代,资深开发的核心价值到底在哪里?| 沸点周刊 7.23
前端·人工智能·后端
橘子星1 小时前
🚀 手把手带你写一个端侧 AI 应用的"加载进度条"与"聊天对话框"
前端·人工智能
37.2℃9951 小时前
专业的Claude Design解决方案
前端·算法
Jolyne_1 小时前
ng-zorro-table列宽resize后宽度是NaN的源码调试记录
前端
liwulin05062 小时前
【ollama】自定义结构化输出
linux·前端·数据库·ollama
前端甜糖2 小时前
记录We码开发者工具的一个bug
前端·javascript
程序员黑豆2 小时前
鸿蒙应用开发教程:以红绿灯切换为例,掌握条件渲染的核心用法
前端·harmonyos
猫3282 小时前
echarts 日常问题解决
前端·javascript·echarts
新中地GIS开发老师2 小时前
地信职业百科④:GIS开发工程师
前端·数据库·gis·webgis·三维gis开发