jQuery random image


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

Really simple jQuery random image


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.