先上图
就是一个简单的弹幕发送功能
弹幕区的页面:
<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', top:item.top+'%',color:'#333',background:item.result.bgColor}">
<image :src="/UploadFiles/2021-04-02/item.result.faceImage">
弹幕区的代码逻辑:
// 弹幕参数
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微信小程序开发之实现一个弹幕评论,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“mpvue微信小程序开发之实现一个弹幕评论”评论...
更新动态
2025年11月03日
2025年11月03日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
