Giter Club home page Giter Club logo

backgroundvideo's Introduction

backgroundVideo - v0.2.4

About

What is backgroundVideo?

backgroundVideo makes your HTML5 <video> behave like the CSS property background-size: cover, making it fully responsive and scaling to aspect ratio. Also included is an optional hardware accelerated parallax effect on the video. If you would like the parallax effect to behave like background-attachment: fixed instead of parallax, you can set parallaxOptions.effect: 1.

Why is this plugin required?

You may be aware of the CSS property object-fill: cover. Unfortunately, this is currently only supported in Chrome (http://caniuse.com/#feat=object-fit). This plugin will allow you to use a video as a responsive background.

Working Examples

Please note: parallax video is most effective on fixed position videos

Browser Support

HTML5 video supported browsers on desktop:

  • IE9+
  • Chrome
  • Firefox
  • Safari
  • Opera

Please note this plugin will not work on mobile devices. Background videos will never work until autoplay is allowed. A responsive image is suggested as fallback

How to use

The HTML structure is the most important part here. The rest of the work will be taken care of by the JavaScript.

For the most basic implementation, add the following to your <body>:

<div id="video-wrap">
    <video id="my-video" preload="metadata" autoplay loop>
        <source src="yourVideoName.mp4" type="video/mp4">
        <source src="yourVideoName.webm" type="video/webm">
    </video>
</div>

Then, before your closing <body> tag add:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="backgroundVideo.js"></script>
<script>
    $(document).ready(function() {
        $(element).backgroundVideo();
    });
</script>

In its most simple form, this will create a video based on the window height and width and apply a Parallax effect of 1.5.

Usage with additional options

<div id="outer-wrap" style="width: 100%; height: 450px;>"
    <div id="vid-wrap">
        <video id="my-video" preload="metadata" autoplay loop>
            <source src="yourVideoName.mp4" type="video/mp4">
            <source src="yourVideoName.webm" type="video/webm">
        </video>
    </div>
</div>
...
...
$(element).backgroundVideo({
    $videoWrap: $('#video-wrap'),
    $outerWrap: $('#outer-wrap'),
    preventContextMenu: true,
    parallaxOptions: {
        offset: 60,
        effect: 1.7
    }
});

Options

Option Type Default Description
$videoWrap jQuery object $('#video-wrap') The div that wraps around the video
$outerWrap jQuery object $(window) The containing div where outer measurements are taken
minimumVideoWidth number 400 Minimum width of the video for scaling purposes
preventContextMenu boolean false Prevents the user from viewing the context menu on the video (prevent right-click/secondary-click)
parallax boolean true Toggle's parallax video feature
parallaxOptions: { effect: 1.5 } number 1.5 The intensity of the parallax effect (1: fixed). Number must be >= 1.
pauseVideoOnViewLoss boolean true Pause the video when the user scrolls out of view

Dependencies

jQuery 2.1.1

License

Copyright (c) 2014 Sam Linnett

Licensed under the MIT license.

backgroundvideo's People

Contributors

linnett avatar andrefbsantos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.