All Projects → nitin42 → React Video Scroll

nitin42 / React Video Scroll

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Video Scroll

Remember Scroll
🎯 A plugin using localStorage to remember element scroll-position when closed the page.
Stars: ✭ 33 (-71.05%)
Mutual labels:  scroll
Vue List Scroller
Simple and easy to use Vue.js component for efficient rendering large lists
Stars: ✭ 65 (-42.98%)
Mutual labels:  scroll
Prognroll
A tiny, lightweight jQuery plugin that creates scroll progress bar on the page.
Stars: ✭ 108 (-5.26%)
Mutual labels:  scroll
Infinite Webl Gallery
Infinite Auto-Scrolling Gallery using WebGL and GLSL Shaders.
Stars: ✭ 42 (-63.16%)
Mutual labels:  scroll
Lax.js
Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.
Stars: ✭ 8,274 (+7157.89%)
Mutual labels:  scroll
Core Components
Accessible and lightweight Javascript components
Stars: ✭ 85 (-25.44%)
Mutual labels:  scroll
React Redux Scroll
Stars: ✭ 30 (-73.68%)
Mutual labels:  scroll
Footer Reveal
A jQuery plugin for easy implementation of the 'fixed/reveal' footer effect. Demo here:
Stars: ✭ 111 (-2.63%)
Mutual labels:  scroll
Simpleparallax.js
Simple and tiny JavaScript library that adds parallax animations on any images
Stars: ✭ 1,075 (+842.98%)
Mutual labels:  scroll
Svelte Infinite Scroll
Infinite Scroll Component to Svelte
Stars: ✭ 102 (-10.53%)
Mutual labels:  scroll
React Scroll Section
React library to provide a declarative scroll to between sections
Stars: ✭ 44 (-61.4%)
Mutual labels:  scroll
React Bscroll
inspired by betterscroll, and fullfilled by React
Stars: ✭ 49 (-57.02%)
Mutual labels:  scroll
Vue Gemini Scrollbar
Custom overlay-scrollbars with native scrolling mechanism for web applications基于原生滚动机制的自定义滚动条
Stars: ✭ 99 (-13.16%)
Mutual labels:  scroll
Dragscroll
micro library for drag-n-drop scrolling style
Stars: ✭ 989 (+767.54%)
Mutual labels:  scroll
Jquery Scrolllock
Locks mouse wheel scroll inside container, preventing it from propagating to parent element
Stars: ✭ 109 (-4.39%)
Mutual labels:  scroll
Scroll Snap Carousel
Carousel based on CSS Scroll Snap functionality
Stars: ✭ 31 (-72.81%)
Mutual labels:  scroll
Materialviewpager
A Material Design ViewPager easy to use library
Stars: ✭ 8,224 (+7114.04%)
Mutual labels:  scroll
React Scroll Parallax
🔮 React components to create parallax scroll effects for banners, images or any other DOM elements
Stars: ✭ 1,699 (+1390.35%)
Mutual labels:  scroll
Rolly
Custom scroll with inertia, smooth parallax and scenes manager
Stars: ✭ 109 (-4.39%)
Mutual labels:  scroll
Pd Select
vue components ,like ios 3D picker style,vue 3d 选择器组件,3D滚轮
Stars: ✭ 101 (-11.4%)
Mutual labels:  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>
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].