I've been attempting to implement a 'random background on refresh' feature for my Tumblr theme. As some may not be aware, Tumblr themes are comprised of HTML alongside embedded CSS and JavaScript.
At the moment, I have been utilizing this particular script:
<script type="text/javascript">
var bg1 = 'http://i.imgur.com/image1.jpg';
var bg2 = 'http://i.imgur.com/image2.jpg';
var bg3 = 'http://i.imgur.com/image3.jpg';
var bg4 = 'http://i.imgur.com/image4.jpg';
var bg5 = 'http://i.imgur.com/image5.jpg';
var randBG=[bg1,bg2,bg3,bg4,bg5];
window.onload=function() {
num=Math.floor(Math.random()*randBG.length);
document.body.style.background='url('+randBG[num]+') no-repeat center center fixed';
</script>
The current implementation works as intended, but it results in screen flickering and negates my "background-size:cover" declaration. Various attempts at image preloading have proved unsuccessful. Since Tumblr does not support PHP and I lack an external hosting option for a PHP file, I am limited in potential solutions.
Hence, there are two primary concerns. How do I randomize backgrounds upon refreshing without experiencing screen flicker, while also retaining the following CSS properties?
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;