Skip to content

Instantly share code, notes, and snippets.

@notepadwebdev
Last active August 29, 2015 13:57
Show Gist options
  • Save notepadwebdev/9795386 to your computer and use it in GitHub Desktop.
Save notepadwebdev/9795386 to your computer and use it in GitHub Desktop.
background cover video
// background cover for position:fixed video
// aspectRatio = original aspect ratio of video
var ww = $(window).width(),
wh = $(window).height(),
wAR = ww / wh,
newW = (wAR < aspectRatio) ? 'auto' : ww,
newH = (wAR < aspectRatio) ? wh : 'auto',
mT = (wAR < aspectRatio) ? 0 : Math.round((el.height() - wh) / 2) * -1,
mL = (wAR < aspectRatio) ? Math.round((el.width() - ww) / 2) * -1 : 0;
el.css({
'height': newH,
'width': newW,
'margin': mT+'px 0 0 '+mL+'px'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment