日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue制作弹幕

發布時間:2023/12/31 vue 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue制作弹幕 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、彈幕效果展示

如上圖所示的效果,這里我們使用vue 制作。


二、使用技術 vue + vue-baberrage

1.安裝:

npm install vue-baberrage

2.引入

方式一:

import Vue from 'vue' import { vueBaberrage } from 'vue-baberrage' Vue.use(vueBaberrage)

方式二:

const vueBaberrage = request('vue-baberrage').vueBaberrage

方式三:

<script src="./dist/vue-baberrage.js"></script>

3.使用

HTML

<div id="app"> <vue-baberrage:isShow= "barrageIsShow":barrageList = "barrageList":loop = "barrageLoop"></vue-baberrage> </div>

JS

import { MESSAGE_TYPE } from 'vue-baberrage'export default {name: 'app',data () {return {msg: 'Hello vue-baberrage',barrageIsShow: true,currentId : 0,barrageLoop: false,barrageList: []}}, methods:{addToList (){this.barrageList.push({id: ++this.currentId,avatar: "./static/avatar.jpg",msg: this.msg,time: 5,type: MESSAGE_TYPE.NORMAL,});...

三、實例演示

這個封裝成一個 vue的組件:

<template><div class="barrages-drop"><vue-baberrage:isShow="barrageIsShow":barrageList="barrageList":maxWordCount="maxWordCount":throttleGap="throttleGap":loop="barrageLoop":boxHeight="boxHeight":messageHeight="messageHeight"></vue-baberrage></div> </template> <script> import Vue from 'vue'; import { vueBaberrage, MESSAGE_TYPE } from 'vue-baberrage';Vue.use(vueBaberrage);export default {name: 'Barrages',data() {return {msg: '馬優晨就是個辣雞~',barrageIsShow: true,messageHeight: 3,boxHeight: 150,barrageLoop: true,maxWordCount: 3,throttleGap: 5000,barrageList: []};},mounted() {this.addToList();},methods: {addToList() {let list = [{id: 1,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 3,barrageStyle: 'red'},{id: 2,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 8,barrageStyle: 'green'},{id: 3,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 10,barrageStyle: 'normal'},{id: 4,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 5,barrageStyle: 'blue'},{id: 5,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 6,barrageStyle: 'red'},{id: 6,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 12,barrageStyle: 'normal'},{id: 7,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 5,barrageStyle: 'red'},{id: 8,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 5,barrageStyle: 'normal'},{id: 9,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 8,barrageStyle: 'red'},{id: 10,avatar: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3064584167,3502823640&fm=26&gp=0.jpg',msg: this.msg,time: 10,barrageStyle: 'yellow'}];list.forEach((v) => {this.barrageList.push({id: v.id,avatar: v.avatar,msg: v.msg,time: v.time,type: MESSAGE_TYPE.NORMAL,barrageStyle: v.barrageStyle});});}} }; </script> <style lang="less"> .barrages-drop {.blue {border-radius: 100px;background: #e6ff75;color: #fff;}.green {border-radius: 100px;background: #75ffcd;color: #fff;}.red {border-radius: 100px;background: #e68fba;color: #fff;}.yellow {border-radius: 100px;background: #dfc795;color: #fff;}.baberrage-stage {position: absolute;width: 100%;height: 212px;overflow: hidden;top: 0;margin-top: 130px;} } </style>

github地址:

https://github.com/superhos/vue-baberrage/blob/master/docs/zh/README.md#plugin-options

總結

以上是生活随笔為你收集整理的vue制作弹幕的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。