Answer the question
In order to leave comments, you need to log in
`
How to wait for an image to load?
There is an asynchronous image acquisition:
let backgroundImg = await fetch(`https://api.unsplash.com/photos/random?orientation=landscape&per_page=1&query=${city},${currWeather},${timeOfTheYear},${timeOfDay}&client_id=${token}`);
backgroundImg = await backgroundImg.json();
backgroundImg = await backgroundImg.urls;
backgroundImg = await backgroundImg.full;
const img = new Image();
img.src = backgroundImg;
img.onload = () => {
console.log('YES');
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question