All Projects → zerosoul → Rc Bullets

zerosoul / Rc Bullets

🌈基于CSS3 Animation,使用React构建的弹幕组件

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Rc Bullets

Css Protips
A collection of tips to help take your CSS skills pro
Stars: ✭ 20,279 (+5086.45%)
Mutual labels:  css3
Danmu.fm
douyutv danmu 斗鱼TV 弹幕助手
Stars: ✭ 315 (-19.44%)
Mutual labels:  danmu
Photon
Clone native desktop UI's like cocoa and develop native feeling applications using web technologies
Stars: ✭ 369 (-5.63%)
Mutual labels:  css3
Ocbarrage
iOS 弹幕库 OCBarrage, 同时渲染5000条弹幕也不卡, 轻量, 可拓展, 高度自定义动画, 超高性能, 简单易上手; A barrage render-engine with high performance for iOS. At the same time, rendering 5000 barrages is also very smooth, lightweight, scalable, highly custom animation, ultra high performance, simple and easy to use!
Stars: ✭ 294 (-24.81%)
Mutual labels:  danmu
Pattern.css
CSS only library to fill empty background with beautiful patterns.
Stars: ✭ 3,481 (+790.28%)
Mutual labels:  css3
Efo
EFO是一个基于SpringBoot和Vue构建的文件分享系统,包括文件的上传与下载,文件的权限管理,远程文件管理等功能。
Stars: ✭ 327 (-16.37%)
Mutual labels:  css3
You Need To Know Css
💄CSS tricks for web developers~
Stars: ✭ 3,777 (+865.98%)
Mutual labels:  css3
Morphext
A simple, high-performance and cross-browser jQuery rotating / carousel plugin for text phrases powered by Animate.css.
Stars: ✭ 384 (-1.79%)
Mutual labels:  css3
Kikoplay
KikoPlay - NOT ONLY A Full-Featured Danmu Player 不仅仅是全功能弹幕播放器
Stars: ✭ 313 (-19.95%)
Mutual labels:  danmu
Mescroll
精致的下拉刷新和上拉加载 js框架.支持vue,完美运行于移动端和主流PC浏览器 (JS framework for pull-refresh and pull-up-loading)
Stars: ✭ 3,775 (+865.47%)
Mutual labels:  css3
Jianshu
仿简书nx+nodejs+nestjs6+express+mongodb+angular8+爬虫
Stars: ✭ 296 (-24.3%)
Mutual labels:  css3
Codrops Scribbler
A responsive HTML template for coding projects with a clean, user friendly design. Crafted with the latest web technologies, the template is suitable for landing pages and documentations.
Stars: ✭ 302 (-22.76%)
Mutual labels:  css3
Vue3 Jd H5
🔥 Based on vue3.0.0, vant3.0.0, vue-router v4.0.0-0, vuex^4.0.0-0, vue-cli3, mockjs, imitating Jingdong Taobao, mobile H5 e-commerce platform! 基于vue3.0.0 ,vant3.0.0,vue-router v4.0.0-0, vuex^4.0.0-0,vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台!
Stars: ✭ 328 (-16.11%)
Mutual labels:  css3
Smart Css Grid
SMART CSS GRID - CSS Framework
Stars: ✭ 291 (-25.58%)
Mutual labels:  css3
Theme Bmw
✋ Smart Voice: Voice for yourself | 微声: 请为自己发声
Stars: ✭ 373 (-4.6%)
Mutual labels:  css3
Html Css
Curso de HTML5 e CSS3
Stars: ✭ 4,917 (+1157.54%)
Mutual labels:  css3
Filters.css
CSS only library to apply color filters.
Stars: ✭ 318 (-18.67%)
Mutual labels:  css3
Blog
记录前端开发日常点滴。为梦想Coding...
Stars: ✭ 386 (-1.28%)
Mutual labels:  css3
Boomjs
JavaScript实现一个有趣的浏览器图片爆炸动画效果
Stars: ✭ 379 (-3.07%)
Mutual labels:  css3
Vue Shiyanlou
😘基于vue2和vuex的复杂单页面应用,20+页面53个API(仿实验楼)✨✨
Stars: ✭ 342 (-12.53%)
Mutual labels:  css3

React 弹幕

🌈 基于 CSS3 Animation,使用 React 构建,可扩展,高性能。

NPM NPM downloads twitter

演示地址

👉zerosoul.github.io/rc-bullets/

demo gif

安装

npm:

npm install --save rc-bullets

yarn:

yarn add rc-bullets

初始化一个简单的弹幕场景

import React, { useEffect, useState } from 'react';
import BulletScreen, { StyledBullet } from 'rc-bullets';

const headUrl='https://zerosoul.github.io/rc-bullets/assets/img/heads/girl.jpg';
export default function Demo() {
  // 弹幕屏幕
  const [screen, setScreen] = useState(null);
  // 弹幕内容
  const [bullet, setBullet] = useState('');
  useEffect(() => {
    // 给页面中某个元素初始化弹幕屏幕,一般为一个大区块。此处的配置项全局生效
    let s = new BulletScreen('.screen',{duration:20});
    // or
    // let s=new BulletScreen(document.querySelector('.screen));
    setScreen(s);
  }, []);
  // 弹幕内容输入事件处理
  const handleChange = ({ target: { value } }) => {
    setBullet(value);
  };
  // 发送弹幕
  const handleSend = () => {
    if (bullet) {
      // push 纯文本
      screen.push(bullet);
      // or 使用 StyledBullet

      screen.push(
        <StyledBullet
          head={headUrl}
          msg={bullet}
          backgroundColor={'#fff'}
          size='large'
        />
      );
      // or 还可以这样使用,效果等同使用 StyledBullet 组件
      screen.push({msg:bullet,head:headUrl,color:"#eee" size="large" backgroundColor:"rgba(2,2,2,.3)"})
    }
  };
  return (
    <main>
      <div className="screen" style={{ width: '100vw', height: '80vh' }}></div>
      <input value={bullet} onChange={handleChange} />
      <button onClick={handleSend}>发送</button>
    </main>
  );
}

特性

  • 支持传入 React 组件,灵活控制弹幕内容和 UI,并提供一个默认样式组件:<StyledBullet/>
  • 弹幕屏幕管理:清屏,暂停,隐藏(后续可能会加入针对单个弹幕的控制)
  • 弹幕动画参数化:运动函数(匀速/ease/步进/cubic-bezier)、时长(秒)、循环次数、延迟等
  • 鼠标悬浮弹幕暂停

常用 API

  • 初始化弹幕屏幕:const screen = new BulletScreen(<queryString>|<HTMLElement>,[<option>]),此处的option和下面的一致,偏向全局初始化,没有则使用默认值,每次发送弹幕不传则使用默认或全局设置,传了则该条弹幕覆盖全局设置。
  • 发送弹幕:const bulletId = screen.push(<string>|<ReactElement>,[<option>])

option

选项 含义 值类型 默认值 备注
top 弹幕位置 string undefined 自已强制定制距离顶部的高度,格式同 CSS 中的 top
trackHeight 轨道高度 string 50px 均分轨道的高度
onStart 自定义动画开始函数 function null e.g.(bulletId,screen)=>{//do something}可以自定义一些动作,比如播放某个音效,在特定时间暂停该弹幕:screen.pause(bulletId)
onEnd 自定义动画结束函数 function null e.g.(bulletId,screen)=>{//do something}可以自定义一些动作,比如播放某个音效
pauseOnClick 鼠标点击暂停 boolean false 再次点击继续
pauseOnHover 鼠标悬停暂停 boolean true 鼠标进入暂停,离开继续
loopCount 循环次数 number/string 1 值为‘infinite’时,表示无限循环
duration 滚动时长 number/string 10 数字则单位为‘秒’,字符串则支持'10s'和'300ms'两种单位
delay 延迟 number/string 0 数字则单位为‘秒’,字符串则支持'10s'和'300ms'两种单位
direction 动画方向 string normal animation-direction支持的所有值
animateTimeFun 动画函数 string linear:匀速 animation-timing-function支持的所有值
  • 弹幕清屏:screen.clear([<bulletId>]),无参则清除全部
  • 暂停弹幕:screen.pause([<bulletId>]),无参则暂停全部
  • 弹幕继续:screen.resume([<bulletId>]),无参则继续全部
  • 隐藏弹幕(滚动继续):screen.hide([<bulletId>]),无参则隐藏全部
  • 显示弹幕:screen.show([<bulletId>]),无参则显示全部
  • 自带的一个弹幕样式组件:<StyledBullet msg="<弹幕内容>" head="<头像地址>" color="<字体颜色>" backgroundColor="<背景色>" size="<尺寸:small|normal|large|huge|自定义大小,基于em机制,默认normal>">

TO DO

  • 弹幕过多时,防重叠处理
  • react hooks 版本:useBulletScreen

自己动手,丰衣足食

克隆项目

git clone https://github.com/zerosoul/rc-bullets.git && cd rc-bullets

本地类库构建

npm i && npm run start

本地 demo

cd example && npm i && npm run start

支持

赞赏码

License

MIT © zerosoul

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].