温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2021-06-04 15:07:51 来源:亿速云 阅读:130 作者:小新 栏目:web开发

小编给大家分享一下mpvue微信小程序开发之怎么实现一个弹幕评论,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

先上图

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

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

弹幕区的页面:

   <div class="content" v-show="doommData.length">
    <div class="textLeft"></div>
    <div class="textItem">
     <p class="text aon" v-if="item.display" v-for="(item,index) in doommData" :key="index" :id="item.id" :>
      <image :src="item.result.faceImage" class="headImg" />
      <span class="name">{{item.result.name}}:</span>
      <span class="text">{{item.result.sendMessage}}</span>
     </p>
    </div>
   </div>

弹幕区的代码逻辑:

// 弹幕参数
class Doomm {
 constructor(result, top, time, color, id) {
  //内容,顶部距离,运行时间,颜色,id(参数可自定义增加)
  /**
   * result数据结构
   * faceImage:"",
   * bgColor: "#57B2FF",
   * sendMessage: "66666",
   * sendTime: "2019-11-06 15:10:15",
   * name: "eve"
   *
   */
  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微信小程序开发之怎么实现一个弹幕评论”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI