html - change the body background every 10 seconds -


i'm looking simple , lightweight code change body background of website (it can go css also) every 10 seconds, it's supposed easy jquery , css, right?

how can that?

you can use javascript's settimeout() function. here example of how use it.

for settimeout(), need 2 parameters, 1 being function, , other integer, how long timeout last.

so instance, can do:

$(function() {     var newbg = ['img1.png', 'img2.jpg', 'img3.png'];     var path="img/";     var = 0;      var changebg = settimeout(function() {         $('body').css({backgroundimage : 'url(' path + newbg[i] + ')'});         if(i == newbg.length)             i=0;         else             i++;     }, 10000); }); 

this creates array of images, specified path. create variable checks length of arraylist, , whether or not need reset variable i.

so hope helps :)


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -