小程序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>
相关推荐
小凡同志11 分钟前
从 Vibe Coding 到 Spec-Driven:AI 编程范式的下一次进化
前端·人工智能·架构
hbstream12 分钟前
受够了Vibe Coding的失控?换个起点,让AI事半功倍
前端·人工智能
chxii13 分钟前
在IIS中开启http跳转到https 和 http2的介绍
前端·http·https
霪霖笙箫28 分钟前
「JS全栈AI Agent学习」六、当AI遇到矛盾,该自己决定还是问你?—— Human-in-the-Loop
前端·面试·agent
煜bart30 分钟前
使用 TypeScript 实现算法处理
开发语言·前端·javascript
Mike_jia42 分钟前
NginxPulse:Nginx日志监控革命!实时洞察Web流量与安全态势的智能利器
前端
打瞌睡的朱尤43 分钟前
微信小程序1~25
微信小程序·小程序
风之舞_yjf1 小时前
Vue基础(31)_插件(plugins)、scoped样式
前端·vue.js
hnxaoli1 小时前
win10小程序(十八)剪切板循环粘贴
python·小程序
M ? A1 小时前
Vue3+TS实战避坑指南
前端·vue.js·经验分享