当前位置: 首页 > news >正文

【uniapp+vue3】scroll-view实现纵向自动滚动及swiper实现纵向自动滚动

scroll-view本身不支持自动滚动,通过scroll-top属性控制滚动,但是不可以循环滚动

		<scroll-view class="notice-bar" scroll-y="true" ref="scrollViewRef" :scroll-top="data.scrollViewTop"scroll-with-animation><view class="carousel-wrapper"><view class="notice-item" v-for="(item,index) in data.notices"    		:key='index'><image :src="item.icon" alt=""></image><text class="notice-text">{{item.text}}</text></view></view></scroll-view>
<script lang="ts" setup>
import { reactive, getCurrentInstance, onMounted, onUnmounted, ref } from "vue";
const data = reactive({notices: [{icon: "/static/images/common/1.png",text: "这是第1条滚动通知"},{icon: "/static/images/common/2.png",text: "这是第2条滚动通知"},{icon: "/static/images/common/3.png",text: "这是第3条滚动通知"},],timer: null,currentIndex: 0,scrollViewTop: 0})onMounted(() => {startScroll();})onUnmounted(() => {stopScroll()})function startScroll() {if (data.notices.length <= 1) returndata.timer = setInterval(() => {data.currentIndex++;if (data.currentIndex >= data.notices.length) {			stopScroll()} else {data.scrollViewTop = data.currentIndex * 30}}, 1000);}function stopScroll() {clearInterval(data.timer);data.timer = null;}</script>
	.invite-rules {display: flex;justify-content: center;text-align: center;height: 50rpx;line-height: 50rpx;		.notice-bar {				width: 60%;height: 100%;padding: 0 15rpx;margin-top: 25rpx;margin-right: 25rpx;background-color: rgba(87, 184, 253, .5);border-radius: 25rpx;white-space: nowrap;.carousel-wrapper {				display: inline-block;				.notice-item {display: flex;margin-top: 10rpx;					image {width: 40rpx;height: 40rpx;border-radius: 50%;margin-right: 10rpx;}.notice-text {margin-right: 10rpx;font-size: 18rpx;color: #FFFFFF;line-height: 36rpx;}}}}

在这里插入图片描述
使用swiper组件实现很简单,封装下即可用,且支持衔接滑动

<template><view class=""><swiper :autoplay="true" :interval="3000" indicator-color="#999" indicator-active-color="#333" circular verticalclass="notice-bar"><swiper-item v-for="(item, index) in list" :key="index" class="notice-item "><image :src="item.imageUrl" class="notice-image"></image><text class="notice-text">{{ item.text }}</text></swiper-item></swiper></view>
</template><script lang="ts" setup>const props = defineProps({list: Array,});
</script><style lang="scss" scoped>.notice-bar {display: flex;width: 410rpx;height: 50rpx;line-height: 50rpx;padding: 0 15rpx;margin-top: 25rpx;margin-right: 25rpx;background-color: rgba(87, 184, 253, .5);border-radius: 25rpx;white-space: nowrap;.notice-item {display: flex;// justify-content: center;align-items: center;.notice-image {width: 40rpx;height: 40rpx;border-radius: 50%;margin-right: 10rpx;}.notice-text {margin-right: 10rpx;font-size: 18rpx;color: #FFFFFF;line-height: 36rpx;}}}
</style>

父组件中使用

<view class="invite-rules"><scrollSwiper :list="data.notices" /><view class="rules" >xxxx</view></view>
.invite-rules {display: flex;justify-content: center;text-align: center;height: 50rpx;line-height: 50rpx;}
<script lang="ts" setup>
import { reactive, getCurrentInstance, onMounted, onUnmounted, ref } from "vue";
import scrollSwiper from './component/scrollSwiper.vue'
const data = reactive({notices: [{imageUrl: "/static/images/common/1.png",text: "这是1条滚动通知"},{imageUrl: "/static/images/common/1.png",text: "这是2条滚动通知"},{imageUrl: "/static/images/common/1.png",text: "这是3条滚动通知"},],})
http://www.lryc.cn/news/212842.html

相关文章:

  • this.refs[‘tagInput‘].refs.input.focus()和this.$refs[‘tagInput‘].focus()区别
  • 电脑硬件坏了,如何维修?
  • elementplus日期时间选择器组件显示很窄
  • 第三方软件测评选择远程测试好还是现场测试好?
  • HTTPS协议:保障网络安全的加密通信协议
  • C++设计模式_21_Iterator 迭代器(理解;面向对象的迭代器已过时;C++中使用泛型编程的方式实现)
  • 有一个 3*4 的矩阵,找出其中值最大的元素,及其行列号
  • 磁盘的命令
  • 一张图讲清楚业务稳定性要如何做:SRE体系化稳定性方案
  • 安卓端GB28181设备接入模块如何实现实时位置订阅(MobilePosition)
  • 11.与JavaScript深入交流-[js一篇通]
  • Ubuntu 搭建 DHCP ivp6 server 步骤
  • 分享大数据分析师前景怎么样? 从事行业有哪些?
  • 通过wordpress能搭建有影响力的帮助中心
  • word页脚设置,页脚显示第几页共有几页设置步骤
  • C语言实现斐波那契数列的多种方法
  • 一文解决:Swagger API 未授权访问漏洞问题
  • Elasticsearch下载安装,IK分词器、Kibana下载安装使用,elasticsearch使用演示
  • springboot自定义404页面
  • C/C++数据结构之时间复杂度和空间复杂度详细解析以及力扣刷题
  • 【需要理解】80 单词搜索
  • 笔记本电脑的键盘鼠标如何共享控制另外一台电脑
  • 【计算机网络】(谢希仁第八版)第二章课后习题答案
  • 笔记软件Notability mac中文版软件功能
  • 【C++的OpenCV】第十四课-OpenCV基础强化(三):Mat元素的访问之data和step属性
  • Springmvc 讲解(1)
  • 超级英雄的导航之旅:动态路由和嵌套路由
  • 发现个好玩的 Windows微信对话框换行
  • Vue3最佳实践 第八章 ESLint 与 测试 ( Jest )
  • 【抓包分析】通过ChatGPT解密还原某软件登录算法实现绕过手机验证码登录