mpvue微信小程序開發(fā)之實現(xiàn)一個彈幕評論
更新時間:2019年11月24日 08:06:31 作者:我正經(jīng)七百九十九
這篇文章主要介紹了mpvue小程序開發(fā)之 實現(xiàn)一個彈幕評論功能,本文通過實例講解的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
先上圖
就是一個簡單的彈幕發(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; } } //隨機字體顏色 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; // 設置一個開關(guān) return function(item) { if (!canUse) { return false; } // 如果開關(guān)已經(jīng)關(guān)掉了就不用往下了 canUse = false; // 利用閉包剛進來的時候關(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)一個彈幕評論,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
相關(guān)文章
Vue3之組件狀態(tài)保持KeepAlive的簡單使用
這篇文章主要介紹了Vue3之組件狀態(tài)保持KeepAlive的簡單使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05element el-tree組件的動態(tài)加載、新增、更新節(jié)點的實現(xiàn)
這篇文章主要介紹了element el-tree組件的動態(tài)加載、新增、更新節(jié)點的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-02-02