css 字幕闪烁

1、html

<!-- 滚动字幕 -->
<view class="marque_notice" wx:if="{{flag && roll_notice.length > 0}}">
  <view class="roll_notice" catchtap="goProduct" data-value="{{roll_notice[count].product_id}}">
    <image src="{{roll_notice[count].avatar}}"/>
    <text class="one-nowrap">{{count}}{{roll_notice[count].remark}}</text>
    <van-icon name="arrow"></van-icon>
  </view>
</view>

2、css

/*闪烁字幕*/
.marque_notice {
  animation: marque-notices 3.1s;
}
@keyframes marque-notices{
  0% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
.roll_notice {
  display: flex;
  align-items: center;
  position: absolute;
  z-index: 1;
  max-width: 70vw;
  top: 65px;
  left: 15px;
  color: #ffffff;
  background-color: rgba(0,0,0,0.5);
  border-radius: 20px;
  padding: 2px 5px;
  font-size: 14px;
  box-sizing: border-box;
}
.roll_notice image {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}
.roll_notice text {
  margin-left: 5px;
  position: relative;
  font-size: 12px;
}

3、js

data: {
    roll_notice: [],
    count: 0,
    countFlag: 0,
    flag: true
  },
/**
 * 滚动字幕数组
 */
getRollNotice() {
  fn.get('scores/user_logs', { type: 1 }, res => {
    if (res.status === 'success') {
      this.setData({ roll_notice: res.data });
      setTimeout(this.timer, 3100);
    }
  });
},
/**
 * 头部淡出淡出动画
 */
timer() {
  if (this.data.countFlag % 2 === 1) {
    this.setData({
      count: this.data.count + 1,
      flag: !this.data.flag,
      countFlag: this.data.countFlag + 1
    });
  } else {
    this.setData({
      flag: !this.data.flag,
      countFlag: this.data.countFlag + 1
    });
  }
  if (this.data.count === this.data.roll_notice.length) {
    this.setData({
      count: 0,
      countFlag: 0
    });
  }
  setTimeout(this.timer, 3100);
}

4、完成了,看效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值