You are viewing limited content. For full access, please sign in.

Question

Question

Random Wallpaper from Selection on Form Load

asked on February 21, 2018

Good Afternoon Everyone,

Curious if anyone has gotten creative with their CSS and JavaScript  to change their form wallpaper randomly from a selection of images when the form loads.  So each time the form loads, it could be 1 of 4 different wallpapers.  I'm very curious if this is possible and would love to see how you were able to accomplish it.

 

Thanks!

 

Drew

0 0

Replies

replied on February 21, 2018

Figures as soon as I posted this I figured it out.  Just in case someone else is looking to do this, here is the javascript code.  Just make sure to update the "file path to image 1" and so on with the actual image paths


$(document).ready(function(){
var images=['File Path to Image 1',
            'file path to image 2',
            'file path to image 3',
            ];

var randomNumber = Math.floor(Math.random() * images.length);
var bgImg = 'url(' + images[randomNumber] + ')';

$('body').css({'background':bgImg, 'background-size':'cover','background-position':'center',
              'background-attachment':'fixed', 'background-repeat':'no-repeat',  });

});

 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.