Posted By

ira on 04/02/09


Tagged

css jquery


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

benrudolph
rickfu
5h4rk
vali29
lsabin
aaronmoodie
lawrens
laurentzziu
estevancarlos
Some0ne


random bg image


 / Published in: jQuery
 

really simple random bg image. Save images starting at 1.jpg. Put in your jquery selector. Etc, etc.

  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  

Comments

RSS Icon Subscribe to comments
Posted By: i-am-andy on September 1, 2011

Thanks this works great

Posted By: i-am-andy on September 1, 2011

Thanks this works great

You need to login to post a comment.