Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active May 20, 2018 05:59
Show Gist options
  • Select an option

  • Save miguelmota/6b2ec8c9bbd38c99c340 to your computer and use it in GitHub Desktop.

Select an option

Save miguelmota/6b2ec8c9bbd38c99c340 to your computer and use it in GitHub Desktop.
Video scale transform
function updateScale() {
var $videoContainer = $('.video-container');
var $video = $videoContainer.find('video');
var containerWidth = $videoContainer.width();
var containerHeight = $videoContainer.height();
var mediaAspect = 16/9;
var containerAspect = containerWidth / containerHeight;
var transformOrigin = '50% 50%';
var scale = (containerAspect < mediaAspect) ? (mediaAspect / containerAspect) : (containerAspect / mediaAspect);
$video.css({
'transform': 'scale('+ scale +')',
'transform-origin': transformOrigin,
});
}
$(window).on('resize.bg-video', updateScale);
@miguelmota
Copy link
Author

@caseymhunt not exactly, it's just namespacing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment