Skip to content

Commit

Permalink
Merge pull request #12 from samAbeywickrama/feat/samAbeywickrama/#4
Browse files Browse the repository at this point in the history
Feat/sam/abeywickrama/#4
  • Loading branch information
samAbeywickrama authored Feb 23, 2020
2 parents a6a86f7 + 699e916 commit b47e372
Show file tree
Hide file tree
Showing 8 changed files with 12,301 additions and 8,392 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,34 @@ import poster from "./img/poster.jpg";

[**sandbox**](https://codesandbox.io/s/sharp-poitras-qdync)

## FAQ

1. How to show the poster if video has finished.

This can be implemented with `onEnded` event handler. You could create an overlay and show it at the end of the video. Please have a look at this [**example**](https://github.com/samAbeywickrama/reactjs-videobg/blob/master/examples/cra/src/showPosterOnEnd)



## API

### `<VideoBg />`

| Prop | Type | Default | Required | Description |
| ------------ | --------- | ------- | -------- | ------------------------------------------------------- |
| wrapperClass | `String` | none | no | className name for wrapper element. |
| videoClass | `String` | none | no | className name for video element. |
| loop | `Boolean` | `true` | no | Video will start over again. |
| autoPlay | `Boolean` | `true` | no | Video will start playing as soon as it is ready. |
| poster | `String` | none | no | The image to be shown while the videos are downloading. |
| muted | `Boolean` | `true` | no | Should audio of the video be muted? |
| Prop | Type | Default | Required | Description |
|--------------|------------|---------|----------|---------------------------------------------------------|
| wrapperClass | `String` | none | no | className name for wrapper element. |
| videoClass | `String` | none | no | className name for video element. |
| loop | `Boolean` | `true` | no | Video will start over again. |
| autoPlay | `Boolean` | `true` | no | Video will start playing as soon as it is ready. |
| poster | `String` | none | no | The image to be shown while the videos are downloading. |
| muted | `Boolean` | `true` | no | Should audio of the video be muted? |
| onEnded | `Function` | none | no | Triggers on video end |
| onPlay | `Function` | none | no | Triggeres on play |
| onPlaying | `function` | none | no | Triggers on each time the video loops |

### `<VideoBg.Source />`

| Prop | Type | Default | Required | Description |
| ---- | -------- | ------- | -------- | -------------------------------- |
|------|----------|---------|----------|----------------------------------|
| src | `String` | none | yes | static file or video file source |
| type | `String` | none | yes | video type |

Expand Down
19,929 changes: 11,754 additions & 8,175 deletions examples/cra/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/cra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"react": "16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1",
"react-scripts": "^3.4.0",
"reactjs-videobg": "file:../.."
},
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions examples/cra/src/showPosterOnEnd/ShowPosterOnEnd.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.overlay {
background: url(../img/poster.jpg);
background-size: cover;
width: 100vw;
height: 100vh;
position: fixed;
z-index: 1;
}
.form {
position: relative;
z-index: 2;
}
41 changes: 41 additions & 0 deletions examples/cra/src/showPosterOnEnd/ShowPosterOnEnd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from "react";
import VideoBg from "reactjs-videobg";
import ogg from "../videos/Neon.ogg";
import webm from "../videos/Neon.webm";
import mp4 from "../videos/Neon.mp4";
import poster from "../img/poster.jpg";
import "../styles.css";
import './ShowPosterOnEnd.css';

function ShowPosterOnEnd() {

const [isEnded, setIsEnded] = useState(false)

const handleOnEnded = () => {
setIsEnded(true)
}

return (
<div className="App">
<VideoBg
poster={poster}
onEnded={handleOnEnded}
loop={false}
>
<VideoBg.Source src={ogg} type="video/ogg" />
<VideoBg.Source src={webm} type="video/webm" />
<VideoBg.Source src={mp4} type="video/mp4" />
</VideoBg>

<div className="form">
<input type="text" placeholder="Email" />
<input type="password" placeholder="Password" />
<button>Login</button>
</div>

{isEnded && <div className='overlay'></div>}
</div>
);
}

export default React.forwardRef(ShowPosterOnEnd);
Loading

0 comments on commit b47e372

Please sign in to comment.