mpvue微信小程序開發(fā)之實現(xiàn)一個彈幕評論
更新時間:2019年11月24日 08:06:31 作者:我正經(jīng)七百九十九
這篇文章主要介紹了mpvue小程序開發(fā)之 實現(xiàn)一個彈幕評論功能,本文通過實例講解的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
先上圖

就是一個簡單的彈幕發(fā)送功能
彈幕區(qū)的頁面:
<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="item.result.faceImage" class="headImg" />
<span class="name">{{item.result.name}}:</span>
<span class="text">{{item.result.sendMessage}}</span>
</p>
</div>
</div>
彈幕區(qū)的代碼邏輯:
// 彈幕參數(shù)
class Doomm {
constructor(result, top, time, color, id) {
//內(nèi)容,頂部距離,運行時間,顏色,id(參數(shù)可自定義增加)
/**
* result數(shù)據(jù)結(jié)構(gòu)
* 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;
}
}
//隨機(jī)字體顏色
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("");
}
//節(jié)流函數(shù)
function throttle(fn, wait) {
var canUse = true; // 設(shè)置一個開關(guān)
return function(item) {
if (!canUse) {
return false;
} // 如果開關(guān)已經(jīng)關(guān)掉了就不用往下了
canUse = false; // 利用閉包剛進(jìn)來的時候關(guān)閉開關(guān)
setTimeout(() => {
fn(item);
canUse = true; // 執(zhí)行完才打開開關(guān)
}, wait);
};
}
//添加彈幕列表
async barrageCyclic() {
await this.Arr.forEach((ele, i) => {
//往彈幕列表里面添加數(shù)據(jù)
this.doommList.push(
new Doomm(
ele,
Math.ceil(Math.random() * 70 + 10),
Math.floor(Math.random() * 20 + 10),
getRandomColor(),
i
)
);
});
this.doommData = this.doommList;
},
總結(jié)
以上所述是小編給大家介紹的mpvue微信小程序開發(fā)之實現(xiàn)一個彈幕評論,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
相關(guān)文章
vue在mounted中window.onresize不生效問題及解決
這篇文章主要介紹了vue中在mounted中window.onresize不生效問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue3中實現(xiàn)代碼高亮的兩種方法(prismjs和highlight.js)
最近忙著開發(fā)自己的博客系統(tǒng),在做界面展示的時候,需要讓代碼高亮,于是經(jīng)過在網(wǎng)上查閱,發(fā)現(xiàn)有兩款比較好用的插件實現(xiàn)代碼高亮,分別是prismjs和highlight.js,下面我分別介紹下,方便給需要的同學(xué)參考2025-04-04
實現(xiàn)shallowReadonly和isProxy功能示例詳解
這篇文章主要為大家介紹了實現(xiàn)shallowReadonly和isProxy功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12

