if('objectFit' in document.documentElement.style === false) {
var container = document.getElementsByClassName('js-box');
for(var i = 0; i < container.length; i++) {
var imageSource = container[i].querySelector('img').src;
container[i].querySelector('img').style.display = 'none';
container[i].style.backgroundSize = 'cover';
container[i].style.backgroundImage = 'url(' + imageSource + ')';
container[i].style.backgroundPosition = 'center center';
}
}
Thanks to https://pawelgrzybek.com/image-tag-vs-background-property/ (check this website for explanation)
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.