通告栏-文字上下轮播 | uniapp实现

组件使用

<NoticeBar :list="notice"></NoticeBar>
<!-- NoticeBar 组件名 -->

属性

属性名 类型 默认值 说明
list Array 暂无消息 消息集合
color String #de8c17 文字颜色
bgColor String #fffbe8 整个横条的背景色
switchTime Number 5 每条消息切换时间

组件源码(需要自行引入)

<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>
posted @   槑孒  阅读(1074)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示