Created
March 8, 2017 20:28
-
-
Save TheMartes/23881e406b924720295cd340e5326c42 to your computer and use it in GitHub Desktop.
This JavaScript is supossed to make video responsive in IE 6+
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 JavaScript is supossed to make video responsive in IE 6+ | |
export default function(el) { | |
if (isIe()) { | |
let videoEl = el.querySelector('video'); | |
let ration = (1920 / 1080); | |
el.classList.add('ie-fix'); | |
if (dimensions(el).height > (dimensions(videoEl).width / ration)) { | |
let newWidth = dimensions(el).height * ration; | |
videoEl.style.top = '0'; | |
videoEl.style.left = '50%'; | |
videoEl.style.width = newWidth + 'px'; | |
videoEl.style.marginLeft = ((newWidth / 2) * (-1)) + 'px'; | |
} | |
else if (dimensions(el).width > (dimensions(videoEl).height * ration)) { | |
let newHeight = dimensions(el).width / ration; | |
videoEl.style.left = '0'; | |
videoEl.style.top = '50%'; | |
videoEl.style.height = newHeight + 'px'; | |
videoEl.style.marginTop = ((newHeight / 2) * (-1)) + 'px'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment