Random the CSS background
Today, I want a personal blog to another background background, are now popular written in CSS inside.
Chose a few photos, but CSS can only set a background.
As
A 2 3 | body { url ( http : //img401 .imageshack .us/img401/ 7982 /speedlikecy01.jpg ) center no-repeat background: url (http: / / img401. imageshack .us/img401 / 7982 / speedlikecy01.jpg) center no-repeat } |
But can only be set to one, feeling a little boring.
Think of Ideal, each time you open the blog will randomly display a different background.
Random CSS background rotater
Find on the Internet, but must be embedded in web pages inside. It simply is to modify the php or html.
I want a URL to the css background, then automatically and randomly display a different background.
Ideal plus a search on the network, and finally thought of using a simple PHP to achieve.
A 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <? Php / ************************************************* ****************************** * Please Do Not the delete the message for the debug * Title: random_css_background.php * Version: 1.0 @ July 09, 2010 * Author: speedlikecy * Website: speedlikecy.001zone.com ************************************************** ****************************** You can get the detail from here http://diy.001zone.com/blog/352/random-css-background Check the sample speedlikecy.001zone.com Please feel free to use it and to contact me for any reason Feature: The Random and the rotate the output the images Link, for the the style of the CSS Usage: 1.Download this sample code and edit. "Random_css_background.php" 2.Upload to website. 3.Replace the URL at CSS style. "Background: url (http://example.com/random_css_background.php)" ************************************************** **************************************************************** / / / The set the images urls in / / Set the location of the picture array ( $ Images = array ( "Http://img541.imageshack.us/img541/378/smilesn.jpg", "Http://img401.imageshack.us/img401/7982/speedlikecy01.jpg", "Http://img338.imageshack.us/img338/9566/speedlikecy02.jpg", "Http://img535.imageshack.us/img535/75/taiwanlanyu.jpg", "Http://img686.imageshack.us/img686/1931/togetherhand.jpg", ); / / Random function / / Random number function time ( ) ) ; srand ( time ()); / / Set the images number in (rand ()% 5); the this the sample is 5 / / Set the number of pictures ( rand ( ) % 5 ) ; $ Random = ( rand ()% 5); / / The output to the url / / Output results 'Location:' . $images [ $random ] ) ; the header ('Location:' $ images [$ random]); ?> |
How to use:
random_css_background.zip
Copy or download the above code, modify, upload to the Internet.
Modify the CSS, such as background: url (http://example.com/random_css_background.php).
Completed.
Example:
speedlikecy.001zone.com
Each tour will randomly replace the background image.
Other use:
CSS + DIV.
A 2 3 | # Random_img { url ( http://example.com/random_css_background.php ) center no-repeat ; background: url (http://example.com/random_css_background.php) center no-repeat; } |
A
| <div id="random_img"> <! --- your contain ---> </ div> |
Direct calls to
A
| <img src="http://example.com/random_css_background.php"/> |
No. related the posts.






