Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- $(window).on('resize', scaleVideo);
- var vid = document.getElementById("video");
- vid.onloadedmetadata = function() {
- scaleVideo();
- };
- function scaleVideo(){
- //GRAVE WINDOW HEIGHT AND WIDTH.
- var windowHeight=$(window).height();//change window height and width to desire container to set identified sections height //and width.
- var windowWidth=$(window).width();
- //GET VIDEO WIDTH AND HEIGHT;
- var videoNativHeight=$('.bg_video')[0].videoHeight;
- var videoNativeWidth=$('.bg_video')[0].videoWidth;
- // SCALE FACTORS
- var heightScaleFactor=windowHeight / videoNativHeight;
- var widthScaleFactor=windowWidth / videoNativeWidth;
- // GET THIS HIGHEST SCALE FACTOR
- if(widthScaleFactor>heightScaleFactor){
- var scale=widthScaleFactor;
- }else{
- var scale=heightScaleFactor;
- }
- var scaledVideoHeight=videoNativHeight * scale;
- var scaledVideoWIdth=videoNativeWidth * scale;
- $('#video').height(scaledVideoHeight);
- $('#video').width(scaledVideoWIdth);
- };
- var $video = $('#video');
- $video.on('canplaythrough', function() {
- this.play();
- });
- });
- autoplay solution
- http://pastebin.com/5S9VW1k2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement