Git Product home page Git Product logo

vue-baberrage's Introduction


VueBaberrage

Barrage plugin for Vue.js.

OverviewOverviewDemoInstallationUsagePlug OptionsRoadmap

Introduction

Baberrage is one of the popular comment perform style in China.

Overview

new_version

GIF performance is not good enough. Please refer to DEMO page

中文文档

Demo

See the DEMO page

Installation

  1. Install package via NPM
npm i vue-baberrage
  1. Install plugin within project
import Vue from 'vue'
import { vueBaberrage } from 'vue-baberrage'
Vue.use(vueBaberrage)

or

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

or

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

Usage

  1. Template isShow and barrageList are necessary.
<div id="app">
<vue-baberrage
      :isShow= "barrageIsShow"
      :barrageList = "barrageList"
      :loop = "barrageLoop"
      >
    </vue-baberrage>
</div>
  1. Script
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
      });
  ...
  1. Already done

Just two step, and add new barrage message by pushing data into the barrageList. You needn't concern about the management of the barrageList, it will be handled by vue-baberrage. Suggest the barrageList store into the Vuex.

Custom Example

New function in version 3.2.0. Support provides VNode to render the barrage.

<vue-baberrage
        ref="baberrage"
        :lanesCount="5"
        :boxHeight= "stageHeight"
        :isShow= "barrageIsShow"
        :barrageList = "barrageList"
        :loop = "barrageLoop"
        :maxWordCount = "60"
        :hoverLanePause = "hoverLanePause"
        >
		<template v-slot:default="slotProps">
			<span style="color: #000">
			{{slotProps.item.data.userName}}: {{slotProps.item.msg}}
			</span>
		</template>
	  </vue-baberrage>

Customized your barrage UI as the slot of component.props.item data same as barrage data. Noticed that, if the width of barrage not fit in stage. You can add the field extraWidth in barrage data.

{
	id: ++this.currentId,
	avatar: "./static/avatar.jpg",
	msg: this.msg,
	data: {
	  userName: 'more data'
	},
	time: 5,
	type: MESSAGE_TYPE.NORMAL,
	extraWidth: 60
}

Since vue-baberrage only count the width of length of the barrage's message.

Plugin Options

isShow

- Default: `true`
- Acceptable-Values: Boolean
- Function: This is the switch that if barrage is displayed.

barrageList

- Default: `[]`
- Acceptable-Values: Array
- Function: The is the container for managing the all barrage messages.

boxWidth

- Default: `parent's Width`
- Acceptable-Values: Number
- Function: Determine the width of the stage.

boxHeight

- Default: `window's Height`
- Acceptable-Values: Number
- Function: Determine the height of the stage.

messageHeight

- Default: `message's Height`
- Acceptable-Values: Number
- Function: Determine the height of the message.

maxWordCount

- Default: 60
- Acceptable-Values: Number
- Function: Determine the word count of the message.

loop

- Default: `false`
- Acceptable-Values: Boolean
- Function: Loop or not.

throttleGap

- Default: 2000
- Acceptable-Values: Number
- Function: The gap time between the message

posRender

- Default: null
- Acceptable-Values: Function
- Function: To customize the lane of babbarrage messages.
- Return: The function muse return the index of the lane.

lanesCount

- Default: 0
- Acceptable-Values: Number
- Function: To fixed the number of the lanes.

Barrage Message Options

id

- Default: `null`
- Acceptable-Values: Number
- Function: For distinguish with other barrage messages.

avatar

- Default: `#`
- Acceptable-Values: String
- Function: Show the avatar of the barrage message.

msg

- Default: `null`
- Acceptable-Values: String
- Function: The content of the barrage message.

barrageStyle

- Default: `normal`
- Acceptable-Values: String
- Function: the css class name of the barrage message.

time

- Default: `10`
- Acceptable-Values: Number
- Function: How long does the barrage message show.(Seconds)

type

- Default: MESSAGE_TYPE.NORMAL
- Acceptable-Values: Symbol
- Function: The type of the barrage message. 
			MESSAGE_TYPE.NORMAL for scroll from right to left. 
			MESSAGE_TYPE.FROM_TOP for fixed on the top of the stage.

extraWidth

- Default: 0
- Acceptable-Values: Number
- Function: Add extra width to the barrage message.

Events

barrage-list-empty when the barrageList is empty will be called.

<vue-baberrage
	      :is-show= "barrageIsShow"
	      :barrage-list = "barrageList"
	      :loop = "barrageLoop"
	      @barrage-list-empty="sayHi"
	      >

Roadmap

Version 0.0.1

  • Realized the basic functionality.

Version 1.0.0

  • Performance improvement.

Version 1.2.0

  • Code specification
  • Performance improvement.

Version 2.1.2

  • Used ES6.
  • Performance improvement.

Version 2.1.9

  • Added Throttling

Version 3.1.0

  • Used Rollup to build.
  • Add posRender attribute for customizing the show up lane of baberrage messages.
  • Fixed issues.

Version 3.2.0

  • Support customize baberrage.
  • Fixed issues.

Future

I am developing Vue-Baberrage-Plus, difference between Vue-Barrage and Vue-Baberrage-Plus is former will be used for a tool, and Plus is a baberrage system.

vue-baberrage's People

Contributors

dependabot[bot] avatar krialy avatar superhos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-baberrage's Issues

头像问题

当原有系统头像是用户名首字母这种头像时,而不是图片头像时,这个插件好像没做对应的处理?后续版本可以考虑?

msg = 111111111

if you set proptype msg : 11111111111
baberrage will have two lines
maybe that is a bug
如果你设置属性 msg 为 111111111
会有两行
我觉得那是一个bug

vue.js引用方式

可以不用VUE全家桶的方式引用吗?直接用vue.js方式引用项目?用这种方式怎么引用呢?有文档步骤吗?

npm失败

MacBook-Pro:Kd_Wap apple$ npm install vue-baberrage
⸨ ░░░░░░⸩ ⠏ extract:vue: sill extract [email protected]
一直卡到这里,进行不下去了

增加弹幕类型

研发plus版本时可以添加像抖音直播一样自下而上的弹幕类型

关于性能问题建议

这两天有一个小项目,需要做弹幕,时间比较赶,就用了这个插件,用了发现性能不太好,19年的mac,i9CPU,能飙到30%多,本来想着聚凑合用了,后来因为需求变了,逻辑比较特别,这个插件实现不了,就只能自己简单写一个能满足需求的简易版,发现性能还行,至少对CPU不会有很明显的消耗,我分析了一下你的原码,性能应该是消耗在了弹幕滚动moveTo函数那里,我建议是别用js来实时计算位置,而是提前计算好要移动的具体(大概是屏幕宽度吧),利用css的animation来实现滚动,利用对象的animationend回调事件来处理弹幕滚动结束的逻辑,目前我是这么实现的,性能提升了很多,但是我只是很简易的做了一个东西,可能考虑不周全,仅供参考

弹幕经常会显示两条一起出现

我开发一个chat系统,当系统有人进入的时候,就系统弹幕有人进入,我发现这个时候并不显示弹幕,而当我输入chat内容的时候,两条消息一起出现了,请问如何解决啊?

SORRY FOR MY LATE REPLY!

承蒙大家厚爱,项目突破了240 STAR。由于个人去了新公司,加班甚多,因此少了时间在此项目上。
看到屯了一页的ISSUES,十分不好意思。
新年新气象,2021年将会重新维护本项目,希望大家可以继续支持。

Thanks for your guys' support.

如何保证this.barrageList这个数组的长度为6?

使用this.barrageList.push(),不断添加到数组中,setInterval(),定时执行这个方法,会不断地给数组添加数据,随后数组会越来越大,咋保证数组长度就为6,新添加一个后,删除原先的!谢谢

pause 和 replay是有问题的

我尝试调用pause和replay方法,发现这两个方法是不起作用的,pause方法里是不是应该清除一下taskQueque而不是仅仅清除fameId

给数组初始值弹幕不显示,使用按钮添加弹幕数据页面会卡死

代码为文档中提供的demo:

<template>
  <div id="app">
    <button @click="addToList">添加弹幕</button>
    <vue-baberrage :isShow="barrageIsShow" :barrageList="barrageList" :loop="barrageLoop"></vue-baberrage>
  </div>
</template>

<script>
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
      });
    }
  }
}
</script>

虽然按照这个 #33 朋友的方法可以做到页面不会立即卡死,但是cpu飙升,且弹幕始终没有出来,
console也没有报错信息

"dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-baberrage":  "^3.2.4"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.4.0",
    "@vue/cli-plugin-eslint": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-template-compiler": "^2.6.11"
  }

是否可以通过样式增加性能

从下面的图片看起来, 弹幕的移动是通过 js 不断修改 transform 属性。
image

这样会导致 dom 频繁更新, 导致部分手机卡顿。
如果就移动位置而言, 是不是由 js 设置初始位置和目标位置就好了? 移动由 css 去做?

New Version Designing.

For more high performance and user experience.
We design to enhancement the structure of the current project.
But this version will also keep updating.

add

为什么不能放上去暂停弹幕?还有点击弹幕,需要做点什么,可现在点击不了。希望下次更新一下,把这2个功能完善一下把

弹幕提前消失

弹幕提前消失,弹幕越长,尾部还有很多,就消失了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.