Posted By

i-am-andy on 09/01/11


Tagged

image random jquery background


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

spee66


jQuery random image


 / Published in: jQuery
 

Really simple jQuery random image

  1. $(document).ready(function(){
  2.  
  3. bgImageTotal=20;
  4.  
  5. randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
  6.  
  7. imgPath=('/my/image/path/'+randomNumber+'.jpg');
  8.  
  9. $('h1').css('background-image', ('url("'+imgPath+'")'));
  10.  
  11. });

Report this snippet  

You need to login to post a comment.