Last active
February 21, 2017 14:17
-
-
Save vincentorback/433484b80e2a069e67f83646e620c67f to your computer and use it in GitHub Desktop.
Replace object-fit elements with a div using background-size: cover
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
/* | |
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