Random Background Images Script

Thursday, September 12 - 06:47 AM

This code is used if you want a different background every time you refresh your blog/theme.

<script type="text/javascript">
// <![CDATA[
var image_array = new Array();
    image_array[0] = "IMAGEURL";
    image_array[1] = "IMAGEURL";
    image_array[2] = "IMAGEURL";
    image_array[3] = "IMAGEURL";
    image_array[4] = "IMAGEURL";

    var rand_path = image_array[Math.floor(Math.random() * image_array.length)];

    $(document).ready(function() {
        $("body").css('background-image', 'url('+rand_path+')');
// ]]>

If you want to add more image, add this part after the last image_array:

image_array[PREVNUMBER+1] = "IMAGEURL";

Also if you want apply that to other places’ background other than the body background, change body to the div name of the place (ex: #sidebar, .post).


© 2013–2022 Copyright Ilma A. All rights reserved.