JSFiddle - React, Tailwind, and code Playground

HTML

<ul id="gallery"><li id="pic1" style="background-image:url('http://a.imageshack.us/img295/5527/loadinggifanimation.gif')"></li></ul>

CSS

li {    
    width:200px;
    height:200px;
    background-repeat:no-repeat;}

JavaScript

var img = new Array();
var num = 1;
img[num] = new Image();
  // Specify the source for each image
var imgSource = "http://www.christianwitnesses.com/sitebuildercontent/sitebuilderpictures/webassets/spaceNASA.jpg";
img[num].onload = function() {
    $("#pic" + num).attr("style", "background-image:url('" + imgSource + "')")
};
img[num].src = imgSource;