Skip to content

Instantly share code, notes, and snippets.

@blivesta
Created August 24, 2017 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blivesta/67347288b3c94f9bb7aac701b94fe9bf to your computer and use it in GitHub Desktop.
Save blivesta/67347288b3c94f9bb7aac701b94fe9bf to your computer and use it in GitHub Desktop.
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