JSFiddle - React, Tailwind, and code Playground
by Michele Marcucci
HTML
<div class="stretcher" id="bg"></div>
CSS
.stretcher {
position: absolute;
left: 0px;
top: 0px;
z-index: -69;
width:100%;
height:100%;
}
JavaScript
function cycle() {
var header = document.getElementById('bg');
var pictures = new Array('http://advancement.georgetown.edu/advent/wallpapers/ui/img/1366x768/SealWP_1366x768.jpg', 'http://www.sonymobile.co.jp/xperia/docomo/so-01d/common/download/wallpaper/1366-768/xperiaplaywp_1366-768_bk02.jpg');
var numPics = pictures.length;
if (document.images) {
var chosenPic = Math.floor((Math.random() * numPics));
header.style.background = 'url(' + pictures[chosenPic] + ')';
header.style.backgroundSize = 'cover';
}
}
cycle();