Created
August 24, 2017 08:55
-
-
Save blivesta/67347288b3c94f9bb7aac701b94fe9bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const FulidPlyr = (parentSelector) => { | |
if (parentSelector === undefined) { | |
parentSelector = '.FulidPlyr' | |
} | |
let element = document.querySelector(parentSelector) | |
let ratio = 16 / 9 | |
let height = window.innerHeight | |
let width = window.innerWidth | |
let windowRatio = width / height | |
let margin = { | |
x: 0, | |
y: 0 | |
} | |
if (windowRatio > ratio) { | |
// console.log('横長') | |
let newHeight = Math.ceil((width / ratio - height) / 2) | |
margin.y = -newHeight + 'px' | |
} else if (windowRatio < ratio) { | |
// console.log('縦長') | |
let newWidth = height * ratio | |
margin.x = Math.floor((newWidth - width) / -2) - 8 + 'px' | |
} | |
element.style.marginLeft = margin.x | |
element.style.marginRight = margin.x | |
element.style.marginTop = margin.y | |
} | |
export default FulidPlyr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment