|
| 1 | +# Responive Video Background Player for Vue ⚡️ |
| 2 | + |
| 3 | +<a href="https://www.npmjs.com/package/vue-responsive-video-background-player"> |
| 4 | + <img src="https://img.shields.io/npm/dt/vue-responsive-video-background-player.svg" alt="Downloads"> |
| 5 | +</a> |
| 6 | +<a href="https://www.npmjs.com/package/vue-responsive-video-background-player"> |
| 7 | + <img src="https://img.shields.io/npm/v/vue-responsive-video-background-player.svg" alt="Version"> |
| 8 | +</a> |
| 9 | +<a href="https://www.npmjs.com/package/vue-responsive-video-background-player"> |
| 10 | + <img src="https://img.shields.io/npm/l/vue-responsive-video-background-player.svg" alt="License"> |
| 11 | +</a> |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +**If you are looking to play videos in the background, you have found the best Vue package for it 😜 (Currently no YouTube videos)** |
| 16 | + |
| 17 | + >***Prerequisites**: Vue 2.x.x |
| 18 | +
|
| 19 | +## Installation in 2 Steps |
| 20 | + |
| 21 | +### 1: Add with npm 💻 |
| 22 | +```bash |
| 23 | + npm install vue-responsive-video-background-player |
| 24 | +``` |
| 25 | + |
| 26 | +### 2a: Install as a component |
| 27 | + |
| 28 | +```javascript |
| 29 | + import VideoBackground from 'vue-responsive-video-background-player' |
| 30 | + |
| 31 | + Vue.component('video-background', VideoBackground); |
| 32 | +``` |
| 33 | +### 2b: Install as a plugin |
| 34 | +```javascript |
| 35 | + import { Plugin } from 'vue-responsive-video-background-player' |
| 36 | + |
| 37 | + Vue.use(Plugin); |
| 38 | +``` |
| 39 | + |
| 40 | +## Usage - (or to make it runnable 🏃♂️) |
| 41 | + |
| 42 | + |
| 43 | +### Easiest version 🔍 |
| 44 | + |
| 45 | +```html |
| 46 | + <video-background |
| 47 | + src="<your-video-path>.mp4" |
| 48 | + style="max-height: 400px; height: 100vh;" |
| 49 | + > |
| 50 | + <h1 style="color: white;">Hello welcome!</h1> |
| 51 | + </video-background> |
| 52 | +``` |
| 53 | + |
| 54 | +### Advanced version 🌐 |
| 55 | + |
| 56 | +```html |
| 57 | + <video-background |
| 58 | + src="<your-default-video-path>.mp4" |
| 59 | + poster="/images/mainfoto.jpg" |
| 60 | + :sources="[ |
| 61 | + {src: '<your-tablet-video-path>.mp4', res: 900, autoplay: true}, |
| 62 | + {src: '<your-mobile-video-path>.mp4', res: 638, autoplay: true, poster: '<your-mobile-background-image-path>.png'} |
| 63 | + ]" |
| 64 | + style="max-height: 400px; height: 100vh;" |
| 65 | + overlay="linear-gradient(45deg,#2a4ae430,#fb949e6b)" |
| 66 | +> |
| 67 | + <h1 style="color: white;">Hallo welcome!</h1> |
| 68 | +</video-background> |
| 69 | +``` |
| 70 | + |
| 71 | +## Props |
| 72 | + |
| 73 | +This package is for responsive videos depicting different video resolution. Have you ever visited my favorite car company <a href="https://tesla.com">Tesla</a>? Have a look, they use a lot of video background videos and are using different resolutions for each device. |
| 74 | + |
| 75 | +### Props values |
| 76 | + |
| 77 | +- `src` (required: `true`) |
| 78 | + |
| 79 | +This is your path to your video. You can just use this value for showing your video in every resolution. |
| 80 | + |
| 81 | +- `poster` (default: `''`) |
| 82 | + |
| 83 | +This is your first background image that is shown before the video is loaded. |
| 84 | + |
| 85 | +- `sources` (default: `[]`) |
| 86 | + |
| 87 | +This is the main reason for this package. I wanted to have the possibility to change the resolution of the video when the resize event is fired. |
| 88 | + |
| 89 | +To make it work, sources is an array that contains objects. For example: |
| 90 | + |
| 91 | +`[{src: '<your-mobile-video-path>.mp4', res: 638, autoplay: true, poster: '<your-mobile-background-image-path>.png'}]` |
| 92 | + |
| 93 | +To make it work you need at least `src, res, autoplay`. |
| 94 | + |
| 95 | +`poster` is optional. |
| 96 | + |
| 97 | +`res` stand for resolution. This example means that between 0px and 638px of the window's width only the mobile video will be shown. After that your default `src`. |
| 98 | + |
| 99 | +- `autoplay` (default: `true`) |
| 100 | + |
| 101 | +The video is going to be played immediately when the video is ready. If you are setting it to false, you can start the video just by `this.$refs.videobackground.player.play()`. But remember to set `ref=videobackground` to the html tag `<video-background>`, so that it can work. |
| 102 | + |
| 103 | +- `overlay` (default: `''`) |
| 104 | +If you love overlays, then copy the overlay from the advanced example. |
| 105 | + |
| 106 | +- `muted` (default: `true`) |
| 107 | + |
| 108 | +Warning. Videos are perhaps not played when unmuted. |
| 109 | + |
| 110 | +- `loop` (default: `true`) |
| 111 | + |
| 112 | +Loops through the video. You can catch the event `ended` to show only the poster. |
| 113 | + |
| 114 | +- `preload` (default: `auto`) |
| 115 | + |
| 116 | +https://www.w3schools.com/tags/att_video_preload.asp |
| 117 | + |
| 118 | +- `objectFit` (default: `cover`) |
| 119 | + |
| 120 | +So the video fits perfectly in the container |
| 121 | + |
| 122 | +## Events |
| 123 | + |
| 124 | +- `ready`: Video is loaded |
| 125 | +- `playing`: Video is playing |
| 126 | +- `error`: Video error |
| 127 | +- `loading`: Video is loading |
| 128 | +- `ended`: Video finished, only when `loop` is set to false |
| 129 | + |
| 130 | + |
| 131 | +## Security |
| 132 | + |
| 133 | +If you discover any security related issues, please don't email me. I'm afraid 😱. [email protected] |
| 134 | + |
| 135 | +## Credits |
| 136 | + |
| 137 | +Now comes the best part! 😍 |
| 138 | +This package is based on |
| 139 | + |
| 140 | + - https://tesla.com |
| 141 | + |
| 142 | +Oh come on. You read everything?? If you liked it so far, hit the ⭐️ button to give me a 🤩 face. |
0 commit comments