栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

mpvue微信小程序开发之实现一个弹幕评论

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mpvue微信小程序开发之实现一个弹幕评论

先上图

就是一个简单的弹幕发送功能

弹幕区的页面:

   
    
    
     

{{item.result.name}}: {{item.result.sendMessage}}

弹幕区的代码逻辑:

// 弹幕参数
class Doomm {
 constructor(result, top, time, color, id) {
  //内容,顶部距离,运行时间,颜色,id(参数可自定义增加)
  
  this.result = result;
  this.top = top;
  this.time = time;
  this.color = color;
  this.display = true;
  this.id = id;
 }
}
//随机字体颜色
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("");
}
//节流函数
function throttle(fn, wait) {
 var canUse = true; // 设置一个开关
 return function(item) {
  if (!canUse) {
   return false;
  } // 如果开关已经关掉了就不用往下了
  canUse = false; // 利用闭包刚进来的时候关闭开关
  setTimeout(() => {
   fn(item);
   canUse = true; // 执行完才打开开关
  }, wait);
 };
}
  //添加弹幕列表
  async barrageCyclic() {
   await this.Arr.forEach((ele, i) => {
    //往弹幕列表里面添加数据
    this.doommList.push(
     new Doomm(
      ele,
      Math.ceil(Math.random() * 70 + 10),
      Math.floor(Math.random() * 20 + 10),
      getRandomColor(),
      i
     )
    );
   });
   this.doommData = this.doommList;
  },

总结

以上所述是小编给大家介绍的mpvue微信小程序开发之实现一个弹幕评论,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/72287.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号