• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    JavaScript
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React component to seek or control the video frame rate on scroll.

react-video-scroll

size

A React component to seek or control the video frame rate on scroll.

Motivation

Go to Oculus Go ๐Ÿ˜„

Demo

Install

npm install react-video-scroll

or if you use yarn

yarn add react-video-scroll

Usage

In order to use this component, you will need to wrap the video element with a source tag under the VideoScroll component.

Example

import React from 'react'
import { render } from 'react-dom'
import { VideoScroll } from 'react-video-scroll'

const setStyles = (wrapperEl, videoEl, playbackRate) => {
  wrapperEl.style.marginTop = `calc(180% - ${Math.floor(videoEl.duration) *
    playbackRate +
    'px'})`
  wrapperEl.style.marginBottom = `calc(180% - ${Math.floor(videoEl.duration) *
    playbackRate +
    'px'})`
}

function App() {
  return (
    <VideoScroll
      onLoad={props =>
        setStyles(props.wrapperEl, props.videoEl, props.playbackRate)
      }
      playbackRate={15}
      style={{ position: 'sticky' }}
    >
      <video
        tabIndex="0"
        autobuffer="autobuffer"
        preload="preload"
        style={{ width: '100%', objectFit: 'contain' }}
        playsInline
      >
        <source type="video/mp4" src="./oculus.mp4" />
      </video>
    </VideoScroll>
  )
}

render(<App />, document.getElementById('root'))

Download oculus.mp4, place it in the public folder which you're serving and then run the example.

API

VideoScroll Component

Props

playbackRate

type: number

Description: Set the playback rate when seeking the video on scroll.

<VideoScroll playbackRate={20}>
  <video>
    <source type="video/mp4" source="some_file.mp4" />
  </video>
</VideoScroll>
onScroll

type: function

Return type: void

Description: onScroll is invoked when the page is scroll. It receives the following arguments -

  • wrapperEl - Reference to video wrapper i.e VideoScroll component

  • videoEl - Reference to video element

  • currentFrame - Current frame / current time of video

  • playbackRate - Playback rate

  • duration - Duration of video

const onScroll = (props) => {
  const { currentFrame } => props

  setState({ frame: Math.floor(currentFrame)})
}

<VideoScroll onScroll={onScroll}>
  <video><source type="video/mp4" src="some_file.mp4" /></video>
</VideoScroll>
onLoad

type: function

Return type: void

Description: onLoad is invoked when the video is finished loading. Use onLoad to update the height of video wrapper or video element, or applying some other styles to adjust the video on the page. It receives the following arguments -

  • wrapperEl - Reference to video wrapper i.e VideoScroll component

  • videoEl - Reference to the video element

  • playbackRate - Playback rate of video

const onLoad = (props) => {
  const { wrapper, playbackRate, el } = props

  wrapper.style.marginTop = `calc(180% - ${Math.floor(el.duration) *
    playbackRate +
    'px'})`
  wrapper.style.marginBottom = `calc(180% - ${Math.floor(el.duration) *
    playbackRate +
    'px'})`
}

<VideoScroll onLoad={onLoad}>
  <video><source type="video/mp4" src="some_file.mp4" /></video>
</VideoScroll>
horizontalScroll

type: boolean

default: false

Description: Set horizontalScroll to true for seeking the video on horizontal scroll. Set the styles of wrapper or video element using onLoad callback before setting the value for horizontalScroll.

By default, the video will seek on scrolling vertically.

<VideoScroll horizontalScroll={true}>
  <video>
    <source type="video/mp4" src="some_file.mp4" />
  </video>
</VideoScroll>
setCurrentFrame

type: Function

Return value: number

Description: Use setCurrentFrame to set the current frame of video. By default, the frame rate is managed internally using pageXOffset and pageYOffset value. setCurrentFrame receives the following arguments -

  • duration - Duration of video

  • playbackRate - Playback rate of video

setCurrentFrame should return a number value for setting the current frame of a video.

const setFrame = (props) => {
  const { duration, playbackRate } = props

  return window.pageYOffset / 20 - playbackRate
}

<VideoScroll setCurrentFrame={setFrame} horizontalScroll={true}>
  <video>
    <source type="video/mp4" src="some_file.mp4" />
  </video>
</VideoScroll>

More Repositories

1

react-perf-devtool

A browser developer tool extension to inspect performance of React components.
JavaScript
2,324
star
2

react-imgpro

๐Ÿ“ท Image Processing Component for React
JavaScript
2,176
star
3

terminal-in-react

๐Ÿ‘จโ€๐Ÿ’ป A component that renders a terminal
JavaScript
2,124
star
4

redocx

๐Ÿ“„ Create word documents with React
JavaScript
1,389
star
5

Making-a-custom-React-renderer

Tutorial on how to make a custom React renderer
JavaScript
1,286
star
6

animate-components

โœจ Elemental components for doing animations in React
JavaScript
909
star
7

React-Web-AR

๐Ÿ•ถ๏ธ Augmented Reality on web with React
JavaScript
571
star
8

react-color-extractor

A React component which extracts colors from an image
JavaScript
351
star
9

Python-Automation

๐Ÿ’ป These are some projects which I worked upon to automate stuffs using python
Python
246
star
10

Animated-Timeline

๐Ÿ”ฅ Create timeline and playback based animations in React
JavaScript
197
star
11

glamorous-primitives

๐Ÿ’„ style primitive React interfaces with glamorous
JavaScript
92
star
12

react-tint

A React component that applies image processing filters to an image using Processing
JavaScript
87
star
13

react-color-tools

A set of tools as React components for working with colors ๐ŸŽจ
JavaScript
87
star
14

shaping-functions

Visualisation of shaping functions
JavaScript
75
star
15

linkify-markdown

๐Ÿš€ A cli tool which automatically add references to issues, pull requests, user mentions and forks to a markdown file.
JavaScript
69
star
16

react-handy-renderer

โœ๏ธ Draw 2D primitives in sketchy style with React
JavaScript
61
star
17

generative-designs

A collection of generative design React components
JavaScript
58
star
18

stylus-in-react

๐Ÿ’„ Style React components with Stylus
JavaScript
54
star
19

react-text-fun

React meets Blotter.js
JavaScript
52
star
20

react-marker

๐Ÿ–๏ธ Highlight keywords and add colors to your text.
JavaScript
47
star
21

generative-art-tools

Utilities for creating generative art
JavaScript
27
star
22

vscode-glamorous

๐Ÿค™ code snippets for glamorous
21
star
23

Elements-of-physics

Representing elements of physics using React
JavaScript
20
star
24

react-shader-canvas

A small utility function to render the shaders using React
JavaScript
20
star
25

Creating-a-pretty-printer

This is a tutorial for creating a pretty printer in JavaScript
JavaScript
13
star
26

generative-art-snippets

A collection of some useful snippets used in crafting computational art
10
star
27

glamorous-redocx

style redocx components with glamorous ๐Ÿ’„
JavaScript
10
star
28

Tidings

๐Ÿ—ž๏ธ A NLP based news app powered by API.ai
JavaScript
8
star
29

pro-branch

A small package that provides helpers to manage control flow in React
JavaScript
8
star
30

lightup

๐Ÿ’ก A cli tool to quickly launch your react app in an effortless way.
JavaScript
8
star
31

glamorous-stylus

Use Stylus with glamorous
JavaScript
6
star
32

react-image-overlay-effect

A React component for displaying an overlay effect on an image.
TypeScript
5
star
33

component-dot-json

Create and mock stateless React components using JSON
JavaScript
5
star
34

Creating-a-JavaScript-UI-library

This is a tutorial for creating a JavaScript UI library.
5
star
35

babel-preset-hyperapp

A Babel preset for HyperApp
JavaScript
4
star
36

HyperApp-Examples

HyperApp examples
JavaScript
4
star
37

word-classes-visualiser

A small tool based on Compromise NLP to visualise the different word classes from English grammar.
JavaScript
4
star
38

Blog

๐Ÿ“— My writings
3
star
39

algorithmic-art-sketchbook

work in progress
JavaScript
3
star
40

Learning-Processing

A curated list of resources, links and books for learning processing
JavaScript
3
star
41

glam-atom

Glamorous Snippets for Atom
3
star
42

css-to-rn

Convert css string to React Native
JavaScript
3
star
43

myspace

Blog
2
star
44

Working-with-APIs

This repository contains scripts for accessing the third party APIs using Python, JavaScript and Ruby.
Python
2
star
45

T-Box

A command line utility to manage the file uploads, downloads and sharing directly from terminal on your Dropbox.
JavaScript
2
star
46

Nitin-Blog

Welcome to my blog!
2
star
47

personal-blog

My blog
JavaScript
2
star
48

Resume

1
star
49

test-repo

1
star
50

test-draft-releaser

1
star
51

nextjs-netlify-blog-template

TypeScript
1
star
52

Escaper

A small library which provides methods to escape and unescape HTML entities.
JavaScript
1
star
53

nextjs-netlify-blog-template-nitin

1
star
54

insiderin-assignment

assignment
JavaScript
1
star
55

Project-Euler

Contains my solutions to the computational problems at https://projecteuler.net/
Python
1
star
56

nitin42

My personal repository
1
star
57

Real-Markdown

An app that letโ€™s us view the raw markdown on one side and the converted markdown (to HTML) on the other side.
JavaScript
1
star
58

routes-getter

Walks through your routes folder and imports them to your project.
JavaScript
1
star
59

grabvatar

An amazing tool to generate cool avatars for your profile picture given an identifier.
JavaScript
1
star