Git Product home page Git Product logo

moedan's Introduction

moedan

moedan

简单、小巧、实用的弹幕引擎

How to use

npm i moedan -S
import Moedan from 'moedan'
import './moedan/dist/Moedan.css'

const danmakuDada = [
  {
    content: '666',
    time: 1.22
  },
  {
    content: 'did a good job',
    time: 8.90
  }
]
const player = document.querySelector('video.myvoideo')
const Danmaku = new Moedan({
  data: danmakuData,
  container: document.querySelector('.danmaku_container'),
  player
})

player.addEventListener('play', () => {
  Danmaku.play()
})

参数

实例化 Moedan 的参数

container

type: HTMLElement

存放弹幕元素的容器元素

data

type: Array

弹幕数据,数据格式需包含 timecontent 属性,分别代表弹幕在视频的时间和内容

[
  {
    content: '666',
    time: 1.22
  },
  {
    content: 'did a good job',
    time: 8.90
  }
]

player

type: HTMLElement

对应的视频元素

tunnels

type: Number

default: 3

出现弹幕的轨道数量

time

type: Number

default: 6

一条弹幕从出现到消失的时间,单位:秒

API

Danmaku.clear()

清除弹幕

Danmaku.clear()

Danmaku.hide()

隐藏弹幕,一般和隐藏弹幕按钮一块使用

Danmaku.pause()

暂停弹幕,应该和视频一起播放

Player.addEventListener('pause', () => Danmaku.play())

Danmaku.play()

播放弹幕,应该和视频一起播放

Player.addEventListener('play', () => Danmaku.play())

Danmaku.reload()

重新 load 弹幕,应该和视频重播一起使用

Player.addEventListener('ended', () => Danmaku.reload())

Danmaku.seek()

重新定位弹幕,一般和拖动播放器进度条一起使用

// when update video's currentTime
Danmaku.seek()

Danmaku.show()

显示弹幕,一般和显示弹幕按钮一块使用

moedan's People

Contributors

huruji avatar

Watchers

 avatar

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.