Hello everyone, How to make background-image load before the page is displayed?
Htl
<div class="background"></div> CSS
.background { background-image: url(img/background.png); } Hello everyone, How to make background-image load before the page is displayed?
Htl
<div class="background"></div> CSS
.background { background-image: url(img/background.png); } Itβs difficult to do this yourself (as I understood when I was looking for a solution myself).
Found such a script . It allows you to execute the script after downloading an image from the background, for example, using such a code (jQuery):
$('#container').imagesLoaded( { background: true }, function() { console.log('ΠΠ΅ΠΊ-ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π·Π°Π³ΡΡΠΆΠ΅Π½Ρ!'); }); But I, while using it, faced the fact that it does not initialize the backgrounds of pseudo-elements and does not track their loading (even using the DOM readiness function). It is necessary to know, I think.
<script src="https://unpkg.com/imagesloaded@4.1/imagesloaded.pkgd.min.js"></script> <!-- or --> <script src="https://unpkg.com/imagesloaded@4.1/imagesloaded.pkgd.js"></script> added $('#background').imagesLoaded( { background: true }, function() { console.log('ΠΠ΅ΠΊ-ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π·Π°Π³ΡΡΠΆΠ΅Π½Ρ!'); }); all right if yes, then you can still see how the image is loading, I hope I was mistaken somewhere .. - Ruslan LiashenkaΠΠ΅ΠΊ-ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π·Π°Π³ΡΡΠΆΠ΅Π½Ρ! when the picture is fully loaded. Right? Or he does not display it when they have already loaded? Because then something is wrong, and it is strange. - VostokSisters$('#background').css('display', 'block') instead of the console output from my example, for example. - VostokSistersSource: https://ru.stackoverflow.com/questions/619841/
All Articles