I'm trying to get a div background-image property set in React, but no image is shown (and Chrome debugger is not showing background-image as being set for this div in the DOM). Could this have something to do with the image not being loaded? Here's my code:
import './Map.css';
function Map() {
const style = {
backgroundImage: '../assets/gs100.jpeg',
height: "100vh",
backgroundSize: "cover",
}
return (
<div style={style}>
<canvas ></canvas>
</div>
);
}
export default Map;
Here's how I do it outside of React, which works...
var url = "content/maps/gs100.jpeg";
var mapImage = new Image();
mapImage.src = url;
mapImage.onload = function () {
$('#mapBackgroundDiv').css("background-image", "url(" + url + ")");
};