小程序自定义弹幕

微信小程序自定义弹幕

实现思路:定时器 + CSS3

详情在github,欢迎star![点我点我](https://github.com/wuhongwei1/bullet_chat_component)

部分代码:
封装弹幕参数
// 弹幕参数
class Barrage {
  constructor(text, top, time, color) {  //内容,顶部距离,运行时间,颜色(参数可自定义增加)
    this.text = text;
    this.top = top;
    this.time = time;
    this.color = color;
    this.display = true;
    this.id = i++;
  }
}
  //弹幕垂直间距
  //这里看项目需求可更改弹幕运行行数  目前三行
  //记得手动改弹幕的高度
  getRandomDistance() {
    let that = this;
    that.setData({
      barrageTop : that.data.barrageTop == 0 ? 35 : that.data.barrageTop == 35 ? 70 : 0
    })
    return that.data.barrageTop;
  },
  
  //弹幕移动速度
  getRandomTime() {
    let time = [6.5, 7, 7.5, 8, 8.5];
    return time[Math.floor(Math.random()*time.length)]
  },
  
  // 弹幕字体颜色
  getRandomColor() {
    let rgb = []
    for (let i = 0; i < 3; ++i) {
      let color = Math.floor(Math.random() * 256).toString(16)
      color = color.length == 1 ? '0' + color : color
      rgb.push(color)
    }
    return '#' + rgb.join('')
  },

在这里插入图片描述
在这里插入图片描述
ღღღღღღ( ´・ᴗ・)觉得有用的话,请点个赞再走吧!( ´・ᴗ・ )ღღღღღღ

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值