通告栏,文字上下轮播

组件使用:

<NoticeBar :list="notice"></NoticeBar>

组件源码:

<template>
	<view>
		<view class="notice-box" :style="'background-color: '+bgColor+';'">
			<view class="notice-icon">
				<uni-icons
				  :color="color"
				  type="sound"
				  size="14"></uni-icons>
			</view>
			<scroll-view class="notice-content">
				<swiper class="swiper" :autoplay="true" :interval="switchTime*1000" :duration="1500" :circular="true" :vertical="true">
					<swiper-item v-for="(t, index) in list" :key="index" class="notice-content-item">
						<view class="swiper-item">
							<text class="notice-content-item-text" :style="'color: '+color+';'">
								{{t}}
							</text>
						</view>
					</swiper-item>
				</swiper>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			list: {
				type: Array,
				default: ['暂无未读消息']
			}, 
			color: {
				type: String,
				default: '#de8c17'
			},
			bgColor: {
				type: String,
				default: '#fffbe8'
			},
			switchTime: {
				type: Number,
				default: 3
			},
		}
	}
</script>

<style>
	.swiper{
		height: 60upx!important;
	}
	.notice-box{
		width: 100%; 
		height: 60upx; 
		padding: 0 10upx; 
		overflow: hidden; 
		margin: 20upx 0; 
		display: flex; 
		justify-content: flex-start;
	}
	.notice-icon{
		width: 60upx; 
		height: 60upx; 
		line-height: 50upx; 
		text-align: center; 
		position: relative;
	}
	.notice-content{
		width: calc(100% - 220upx); 
		position: relative; 
		font-size: 14px;
	}
	.notice-content-item{
		width: 100%; 
		height: 60upx; 
		text-align: left; 
		line-height: 60upx;
	}
	.notice-content-item-text{
		display: block; 
		white-space: nowrap; 
		text-overflow: ellipsis; 
		overflow: hidden;
	}
	
	@keyframes anotice {
		 0%  {transform: translateY(100%);}
	    30%  {transform: translateY(0);}
	    70%  {transform: translateY(0);}
	   100%  {transform: translateY(-100%);}
	}
</style>

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现微信小程序自动滚动通告,可以使用小程序原生的scroll-view组件,然后通过定时器和动态修改scroll-view的scrollTop属性来实现。 具体步骤如下: 1. 在wxml文件中,使用scroll-view组件,并设置固定高度和滚动方向: ``` <scroll-view class="scroll-view" scroll-y="true" style="height: 70rpx;"> <!-- 在这里放置通告内容 --> </scroll-view> ``` 2. 在js文件中,获取scroll-view组件的节点对象,并定义一个变量用于保存当前滚动的距离: ``` Page({ data: { scrollTop: 0 }, onLoad: function () { // 获取scroll-view组件的节点对象 this.scrollView = this.selectComponent('.scroll-view') } }) ``` 3. 使用定时器,每隔一定时间修改scrollTop属性值,实现自动滚动。 ``` Page({ data: { scrollTop: 0 }, onLoad: function () { // 获取scroll-view组件的节点对象 this.scrollView = this.selectComponent('.scroll-view') // 定时器,每隔1秒滚动一次 setInterval(() => { // 滚动速度,每次滚动5px const speed = 5 // 获取当前scrollTop的值 const scrollTop = this.data.scrollTop // 计算新的scrollTop的值 const newScrollTop = scrollTop + speed // 设置新的scrollTop的值 this.setData({ scrollTop: newScrollTop }) // 如果滚动到了最底部,就回到顶部重新滚动 if (newScrollTop >= this.scrollView.scrollHeight - this.scrollView.height) { this.setData({ scrollTop: 0 }) } }, 1000) } }) ``` 这样就可以实现微信小程序自动滚动通告了。需要注意的是,scroll-view组件的高度和通告内容的高度需要根据实际情况进行调整,以确保能够正常滚动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值