mpvue微信小程序开发之实现一个弹幕评论
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要介绍了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" :style="{'animation-duration':item.time+'s', :item.+'%',color:'#333',background:item.result.bgColor}"> <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, , time, color, id) { //内容,顶部距离,运行时间,颜色,id(参数可自定义增加) /** * result数据结构 * faceImage:"", * bgColor: "#57B2FF", * sendMessage: "66666", * sendTime: "2019-11-06 15:10:15", * name: "eve" * */ this.result = result; this. = ; 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微信小程序开发之实现一个弹幕评论,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,长沙网络推广会及时回复大家的!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程