uniapp垂直滚动公告栏,可上下拖动内容

垂直滚动公告栏

效果图

在这里插入图片描述

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

<script>

	export default {

		props: {
			text: {
				type: String,
				default: '暂无未读消息'
			},
			color: {
				type: String,
				default: '#de8c17'
			},
			bgColor: {
				type: String,
				default: '#fffbe8',

			},
			switchTime: {
				type: Number,
				default: 3
			},
		
		},
		data() {
			return {
				number: 0,
				list: [],
				copyText: '',
				show: '',
			};
		},
		mounted() {
			this.list = this.text.split('|');
			console.log(this.list.length)
			this.show = true;
		},
		watch: {
			text: function() {
				this.show = true;
				if (this.text != this.copyText) {
					this.copyText = this.text;
					this.list = this.text.split('|');
					console.log(JSON.stringify(this.list))
				}
			}
		},
		methods: {
			more() {
				this.show = false;
				this.$emit('more')
			}
		}
	}
</script>

<style>
	.swiper {
		height: 60upx !important;
	}

	.an-notice-box {
		width: 100%;
		height: 60upx;
		padding: 0 10upx;
		overflow: hidden;
		margin: 20upx 0;
		display: flex;
		/* justify-content: flex-start; */
		justify-content: center;
		border-radius: 20rpx;
	}

	.an-notice-icon {
		width: 60upx;
		height: 60upx;
		line-height: 50upx;
		text-align: center;
		position: relative;
	}

	.an-notice-content {
		width: calc(100% - 220upx);
		position: relative;
		font-size: 14px;
	}

	.an-notice-content-item {
		width: 100%;
		height: 60upx;
		text-align: center;
		line-height: 60upx;
	}

	.an-notice-content-item-text {
		display: block;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		/* align-items: center; */
	}

	.an-notice-more {
		width: 130upx;
		height: 60upx;
		font-size: 12px;
		line-height: 60upx;
		text-align: right;
		color: #999;
	}

	@keyframes anotice {
		0% {
			transform: translateY(100%);
		}

		30% {
			transform: translateY(0);
		}

		70% {
			transform: translateY(0);
		}

		100% {
			transform: translateY(-100%);
		}
	}
</style>

在用该组件的时候
引入,注册组件就不多说啦

//template
	<notice-bar :text='noticetext'></notice-bar><notice-bar :text='noticetext'></notice-bar >
//js代码
import auctionList from '../../components/auctionlist.vue';

	export default {
	data() {
			return {
				noticetext: '寒雨连江夜入吴|平明送客楚山孤|一片冰心在玉壶',
	        }
	},	
	components: {
			citySelect,
			noticebar,
			auctionList
		},
		}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值