Skip to content

Instantly share code, notes, and snippets.

@Ravenna
Created April 4, 2017 23:33
Show Gist options
  • Select an option

  • Save Ravenna/f2227e35a96a4ccc0b981caa1d904103 to your computer and use it in GitHub Desktop.

Select an option

Save Ravenna/f2227e35a96a4ccc0b981caa1d904103 to your computer and use it in GitHub Desktop.
// BUILD VIDEO SOURCE
var mp4 = $('#home-video-div').attr("data-mpfour");
var webm = $('#home-video-div').attr("data-webm");
$('#bgvid').append('<source src="'+ mp4 +'" type="video/mp4"><source src="'+ webm +'" type="video/webm">');
// SCALE VIDEO SOURCE
$('#home-video-div').delay(200).velocity({ opacity: 1 }, { display: "block" });
var scale = 1;
var videoRatio = 16 / 9;
var viewportRatio = $(window).width() / $(window).height();
if (videoRatio < viewportRatio) {
// viewport more widescreen than video aspect ratio
scale = viewportRatio / videoRatio;
} else if (viewportRatio < videoRatio) {
// viewport more square than video aspect ratio
scale = videoRatio / viewportRatio;
}
$('#bgvid').velocity({
scaleX: scale,
scaleY: scale
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment