Forum Moderators: open
<script type="text/javascript">
var backgroundSrcs = new Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg")
function pickimage()
{
var bgimage=backgroundSrcs[(Math.round(Math.random()*(backgroundSrcs.length-1)))]
document.getElementById("random").style.backgroundImage = "url('" + bgimage + "')";
}
</script>
<body onload="pickimage()">
Is there a way to stop the flicker while maintaining a copy of the div's base background image?
Thanks!
A couple of choices
1. call pickimage() in a small script block immediately after the img element appears in the HTML.
2. Use a document.write() statement to write the image HTML into the page.
BTW, your random code needs changing. Presently, the 7th image will never appear.
Replace Math.round with Math.floor