mpvue微信小程序開發(fā)之實(shí)現(xiàn)一個(gè)彈幕評論
更新時(shí)間:2019年11月24日 08:06:31 作者:我正經(jīng)七百九十九
這篇文章主要介紹了mpvue小程序開發(fā)之 實(shí)現(xiàn)一個(gè)彈幕評論功能,本文通過實(shí)例講解的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
先上圖
就是一個(gè)簡單的彈幕發(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)容,頂部距離,運(yùn)行時(shí)間,顏色,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è)置一個(gè)開關(guān) return function(item) { if (!canUse) { return false; } // 如果開關(guān)已經(jīng)關(guān)掉了就不用往下了 canUse = false; // 利用閉包剛進(jìn)來的時(shí)候關(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ā)之實(shí)現(xiàn)一個(gè)彈幕評論,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
您可能感興趣的文章:
- VUE+Java實(shí)現(xiàn)評論回復(fù)功能
- Vue組件實(shí)現(xiàn)評論區(qū)功能
- vue開發(fā)實(shí)現(xiàn)評論列表
- vue實(shí)現(xiàn)評論列表
- Vue實(shí)現(xiàn)簡單的發(fā)表評論功能
- 使用Vue+Django+Ant Design做一個(gè)留言評論模塊的示例代碼
- vue實(shí)現(xiàn)評論列表功能
- Vuepress 搭建帶評論功能的靜態(tài)博客的實(shí)現(xiàn)
- 簡易Vue評論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn))
- vue實(shí)現(xiàn)文章評論和回復(fù)列表
相關(guān)文章
Vue from-validate 表單驗(yàn)證的示例代碼
本篇文章主要介紹了Vue from-validate 表單驗(yàn)證的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09Vue3之組件狀態(tài)保持KeepAlive的簡單使用
這篇文章主要介紹了Vue3之組件狀態(tài)保持KeepAlive的簡單使用方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05element el-tree組件的動(dòng)態(tài)加載、新增、更新節(jié)點(diǎn)的實(shí)現(xiàn)
這篇文章主要介紹了element el-tree組件的動(dòng)態(tài)加載、新增、更新節(jié)點(diǎn)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02vue+Element-ui實(shí)現(xiàn)登錄注冊表單
這篇文章主要為大家詳細(xì)介紹了vue+Element-ui實(shí)現(xiàn)登錄注冊表單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11