JS and CSS so that each refresh page to create a random background map, of course, my answer is OK, the following is the specific realization of ideas, interested friends can refer to the following
Today, a friend on the Weibo asked me if you can use JS and CSS to make every refresh of the page randomly generated a background picture, of course, my answer is yes. Can do this: 1, with JS to define an image array, which store you want to randomly show the picture code as follows: Var imgarr=["Logo_cn.png", "Baidu_sylogo1.gif", "20120111081906_79.jpg", "20120111081906_76.jpg"]; Here I casually find 4 pictures, gather around alive to see. 2, with JS to generate a random number, of course, this random number from the beginning of 0 to imgarr.length-1 end code as follows: Var index =parseint (Math.random () * (imgarr.length-1)); So we get the current randomly generated picture code as follows: Var currentimage=imgarr[index]; 3, since a random generation of a background map, then use JS to this picture as a background map. The code is as follows: document.getElementById ("Backgroundarea"). Style.backgroundimage= "url (" +currentimage+ ")"; Since this is a demo, I have defined a div with ID backgroundarea on the page, and also set a random background for this div. The code is as follows: <div id= "Backgroundarea" > </div>