random bg image


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.