GithubHelp home page GithubHelp logo

barrage-demo's Introduction

barrage-demo

基于张鑫旭的使用canvas实现和HTML5 video交互的弹幕效果源码改造

效果

image

Project setup

yarn install

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build

区别

去掉了与视频的绑定,根据自然时间来推送弹幕进度,比较适合年会现场等大屏静态互动场景,支持vue直接使用

使用方式

引入canvasBarrage.js

import canvasBarrage from "@/tools/canvasBarrage";
// 弹幕数据
var dataBarrage = [
  {
    value: "speed设为0为非滚动",
    speed: 0,
  },
  {
    value: "time控制弹幕时间,单位秒",
    color: "blue",
  },
  {
    value: "视频共21秒",
  },
  {
    value: "视频背景为白色",
  },
  ...
];

处理数据,这里是为了展示效果根据当前时间造假数据的时间

  mounted() {
    let nowTime = new Date();
    dataBarrage.forEach((item, index) => {
      item.time = nowTime.setTime(nowTime.getTime() + index * 200);
    });
    //创建实例
    this.canvasBarrage = new canvasBarrage("#canvasBarrage", { data: dataBarrage });
    //mounted之后立即播放
    this.canvasBarrage.play();
  }

完整源码可以看github,github上的demo还结合了lottie效果做了特效

License

MIT

barrage-demo's People

Stargazers

Ryan avatar

Watchers

CloudJay 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.