mpvue微信小程序開(kāi)發(fā)之實(shí)現(xiàn)一個(gè)彈幕評(píng)論
先上圖
就是一個(gè)簡(jiǎn)單的彈幕發(fā)送功能
彈幕區(qū)的頁(yè)面:
<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è)開(kāi)關(guān) return function(item) { if (!canUse) { return false; } // 如果開(kāi)關(guān)已經(jīng)關(guān)掉了就不用往下了 canUse = false; // 利用閉包剛進(jìn)來(lái)的時(shí)候關(guān)閉開(kāi)關(guān) setTimeout(() => { fn(item); canUse = true; // 執(zhí)行完才打開(kāi)開(kāi)關(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微信小程序開(kāi)發(fā)之實(shí)現(xiàn)一個(gè)彈幕評(píng)論,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- VUE+Java實(shí)現(xiàn)評(píng)論回復(fù)功能
- Vue組件實(shí)現(xiàn)評(píng)論區(qū)功能
- vue開(kāi)發(fā)實(shí)現(xiàn)評(píng)論列表
- vue實(shí)現(xiàn)評(píng)論列表
- Vue實(shí)現(xiàn)簡(jiǎn)單的發(fā)表評(píng)論功能
- 使用Vue+Django+Ant Design做一個(gè)留言評(píng)論模塊的示例代碼
- vue實(shí)現(xiàn)評(píng)論列表功能
- Vuepress 搭建帶評(píng)論功能的靜態(tài)博客的實(shí)現(xiàn)
- 簡(jiǎn)易Vue評(píng)論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn))
- vue實(shí)現(xiàn)文章評(píng)論和回復(fù)列表
相關(guān)文章
基于Vue.js 實(shí)現(xiàn)簡(jiǎn)易拖拽指令
在 Vue.js 中,我們可以通過(guò)自定義指令的方式來(lái)實(shí)現(xiàn)拖拽功能,使得代碼更加模塊化和可復(fù)用,本文將介紹如何基于 Vue.js 實(shí)現(xiàn)一個(gè)簡(jiǎn)易的拖拽指令,感興趣的朋友跟隨小編一起看看吧2024-04-04Vue from-validate 表單驗(yàn)證的示例代碼
本篇文章主要介紹了Vue from-validate 表單驗(yàn)證的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09Vue3之組件狀態(tài)保持KeepAlive的簡(jiǎn)單使用
這篇文章主要介紹了Vue3之組件狀態(tài)保持KeepAlive的簡(jiǎn)單使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(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),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02vue+Element-ui實(shí)現(xiàn)登錄注冊(cè)表單
這篇文章主要為大家詳細(xì)介紹了vue+Element-ui實(shí)現(xiàn)登錄注冊(cè)表單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11