By including this component, you can make youtube video as HTML page background. This is created based jquery-tubular plugin. Lets see how to use this library.

Using npm

npm install react-tubular --save

Import Tubular component

import Tubular from 'react-tubular';

Usage

Here you can pass ration, youtube video id, mute, repeat, width, z-index of the wrapper, volume increase or decrease range, video starting point.
<Tubular
    ratio = {16/9} // usually either 4/3 or 16/9 -- tweak as needed
    videoId = {'ZCAnLxRvNNc'} // toy robot in space is a good default, no?
    mute = {true}
    repeat = {true}
    width = {window.innerWidth}
    wrapperZIndex = { -1 }
    increaseVolumeBy = { 10 }
    start = { 0 }
    ref={(ref)=>{this.tubular = ref}}/>

Functions

Tubular component provides some functions, which we can call by using ref. Observe below example which calls playVideo, pauseVideo, mute, decreaseVolume, increaseVolume functions
import React from 'react';
import Tubular from 'react-tubular';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.playVideo = this.playVideo.bind(this);
    this.pauseVideo = this.pauseVideo.bind(this);
    this.mute = this.mute.bind(this);
    this.decreaseVolume = this.decreaseVolume.bind(this);
    this.increaseVolume = this.increaseVolume.bind(this);
  }

  playVideo() {
    this.tubular.playVideo();
  }

  pauseVideo() {
    this.tubular.pauseVideo();
  }

  mute() {
    this.tubular.mute();
  }

  decreaseVolume() {
    this.tubular.decreaseVolume();
  }

  increaseVolume() {
    this.tubular.increaseVolume();
  }

  render() {
    return (
      <div>
        <h1>It Works </h1>
        <p>This React project just works with react-tubular</p>
        <h2>Actions</h2>

        <button onClick={this.playVideo}>Play video</button>
        <button onClick={this.pauseVideo}>Pause video</button>
        <button onClick={this.mute}>Mute video</button>
        <button onClick={this.decreaseVolume}>Decrease Volume</button>
        <button onClick={this.increaseVolume}>Increase Volume</button>

        <Tubular
            ratio = {16/9} // usually either 4/3 or 16/9 -- tweak as needed
            videoId = {'ZCAnLxRvNNc'} // toy robot in space is a good default, no?
            mute = {true}
            repeat = {true}
            width = {window.innerWidth}
            wrapperZIndex = { -1 }
            increaseVolumeBy = { 10 }
            start = { 0 }
            ref={(ref)=>{this.tubular = ref}}/>

      </div>
    )
  }
}

1 comment:

  1. All visual media transitions from being a tech gadget to eventually being a true channel for communication. Website video is moving that direction and as a result the demands on quality content, acting and delivery will increase, not decrease. See more video background for website

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts