Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active February 21, 2017 14:17
Show Gist options
  • Save vincentorback/433484b80e2a069e67f83646e620c67f to your computer and use it in GitHub Desktop.
Save vincentorback/433484b80e2a069e67f83646e620c67f to your computer and use it in GitHub Desktop.
Replace object-fit elements with a div using background-size: cover
/*
Demo:
http://codepen.io/vincentorback/pen/ZLLJbB
*/
export function objectFit (el) {
let objectElReplacement = `<div
class="${el.classList}"
style="
background-image:url(${el.getAttribute('src')});
background-size:cover;
background-position:50% 50%;
background-repeat:no-repeat
"></div>`
el.insertAdjacentHTML('afterend', objectElReplacement)
el.parentNode.removeChild(el)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment