Welcome visitor
* Login
* Register
It is currently March 25th, 2019, 3:15 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » HTML



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  random background image
PostPosted: April 14th, 2009, 8:39 pm 

Posts: 46
hi i have 3 images that i would like as the background, and im wondering if there's something like random for html to display a different background image? thank you.


Top
 Profile  
 
  Re: random background image
PostPosted: April 14th, 2009, 10:09 pm 
User avatar

Posts: 86
Html does not have a rand function, on this example i'm gonna use javascript as well. The javascript rand function is not very helpful on this 'cause it gives any number between 0 and 1. What i suggest to do is based on the second the page is loaded, do some math and then apply the background 1, 2 or 3. Hope this helps you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title></title>
    <script type="text/javascript">
        function randBg(){
        var s= new Date();
        s= s.getSeconds();
        n1 = s/2- Math.floor(s/2);
        n2 = s/3- Math.floor(s/3);
        if (n1==0){document.getElementById("bd").style.background = "url(b2.jpg)";}
        else if (n2==0){document.getElementById("bd").style.background = "url(b3.jpg)";}
        else {document.getElementById("bd").style.background = "url(b1.jpg)";}
        }
   
    </script>
</head>
<body id="bd" onLoad="randBg();">


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » HTML


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron