Created
July 29, 2021 19:14
-
-
Save Andrii-Yukhymenko/aca49d0b2b7abee65dfe52ee19c83ced to your computer and use it in GitHub Desktop.
ibg
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
<!--CSS--> | |
.ibg{ | |
background-position: center; | |
background-size: cover; | |
background-repeat: no-repeat; | |
position: relative; | |
} | |
.ibg img{ | |
width: 0; | |
height: 0; | |
position: absolute; | |
top: 0; | |
left: 0; | |
opacity: 0; | |
visibility: hidden; | |
} | |
<!--JS--> | |
function ibg(){ | |
let ibg=document.querySelectorAll(".ibg"); | |
for (var i = 0; i < ibg.length; i++) { | |
if(ibg[i].querySelector('img')){ | |
ibg[i].style.backgroundImage = 'url('+ibg[i].querySelector('img').getAttribute('src')+')'; | |
} | |
} | |
} | |
ibg(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment