vue 组件 (弹幕消息提醒)动画

html
<view class="dmNoticeList" v-if="!empty">
			<view class="list">
				<view v-if="index == nowDmIndex" :class="index == nowDmIndex?'showAndHide':''" class="item" v-for="(item, index) in dmNewList" :key="index">
					<view class="image">
						<images mode="widthFix" :src="item.pic"></images>
					</view>
					<view class="title">{{item.title}}</view>
				</view>
			</view>
		</view>

js

// Data: (假数据)

empty: true,
nowDmIndex: -1, // 当前显示的弹幕块
timer: null, // 弹幕定时器 
dmNewList: [
    {
        title: '**我是1 新订单 五分钟前',
        pic: ''
    },
    {
        title: '**我是2 新订单 一分钟前',
        pic: ''
    },
    {
        title: '**我是3 新订单 三分钟前',
        pic: ''
    }
]
// onload 初始化
 this.DmListOrder();
// 方法区:

    
        DmListOrder(){
			// 时间 
			let time_jg = 5000;
			let that = this;
			that.nowDmIndex = -1;
			this.timer = setInterval( () => {
				let res = {};
				res.data = {list:[]};
				res.total = 3;
				res.data.list = that.dmNewList;
					if(res && res.total > 0) {
						that.dmNewList = res.data.list; //直接赋值
						that.empty = false; 
						// 弹出显示 并隐藏其他
						if(that.nowDmIndex == -1){
							that.nowDmIndex = 0;
						}else if(that.nowDmIndex < (that.dmNewList.length-1) ) {
							that.nowDmIndex += 1;
						}else {
							that.nowDmIndex = 0;
							// that.nowDmIndex += 1;
							// 执行请求新数据 并且返回赋值
							that.clearTimer();
						}
					} else {
						// 如果没有新数据就直接隐藏
					   that.empty = true;
					   that.dmNewList = [];
					   that.nowDmIndex = -1 ;
					}
				
			}, time_jg)
		},
        // 清理定时器 然后再次执行唤起 定时器
		clearTimer (){
		    clearInterval(this.timer);        
			this.timer = null;
            this.dmNewList = [];
			this.timer = setTimeout( () => {
				this.DmListOrder(); //再次执行
			}, 5000)
		},

<style lang="sass">
.dmNoticeList{
	z-index: 888;
	position: fixed;
	left: 1.5rem;
	top: 20%;
	width: fit-content;
	height: 2.5rem;
	animation: showAndHide 5s infinite;
	@keyframes showAndHide {
		0%{top: 15%;opacity: 0;}
		65%{top: 20%;opacity: 1;}
		100%{top: 15%;opacity: 0;}
	}
	.list{
		width: fit-content;
		height: 100%;
		font-size: 30rpx;
		background-color: #353535;
		opacity: 0.7;
		border-radius: 1.25rem;
		color: #fff;
		.item{
			display: flex;
			align-items: center;
			height: 100%;
			width: 100%;
			justify-content: space-between;
			.image{
				width: 2rem;
				height: 2rem;
				margin-right: 0.2rem;
				border-radius: 50%;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.title{
				margin-right:0.7rem;
			}
		}
	}
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值