Created
June 3, 2014 23:54
-
-
Save rayfranco/0910241a88f24f5fb903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.el = document.getElementById('video'); | |
var minW = 1024; | |
var minH = 661; | |
var onResize = function() { | |
var ch, cr, cw, ph, pr, pw, css; | |
if (!this.el) { | |
return; | |
} | |
pw = this.el.videoWidth; | |
ph = this.el.videoHeight; | |
cw = window.innerWidth; | |
ch = window.innerHeight; | |
pr = pw / ph; | |
cr = cw / ch; | |
cw = cw > minW ? cw : minW; | |
ch = ch > minH ? ch : minH; | |
if (cr < pr) { | |
css = { | |
width: ch * pr, | |
height: ch, | |
top: 0, | |
left: -((ch * pr) - cw) * 0.5 | |
}; | |
} else { | |
css = { | |
width: cw, | |
height: cw / pr, | |
top: -((cw / pr) - ch) * 0.5, | |
left: 0 | |
}; | |
} | |
this.el.style.width = css.width+'px'; | |
this.el.style.height = css.height+'px'; | |
this.el.style.top = css.top+'px'; | |
this.el.style.left = css.left+'px'; | |
}.bind(this); | |
this.el.style.position = 'absolute'; | |
// Listen to window resize event | |
window.addEventListener('resize',onResize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment