|
Convenient web based access to our favorite web design Usenet groups
|
 |
This is Interesting: Free Magazines for Graphics designers and webmasters
| Author |
| Thread |
 |
|
|
|
|
|
 |
 |
|
|
 |
 |
Re: randomly change background image with css and javascript? |
 |
|
 |
|
|
|
  07-23-04 - 05:16 PM
|
Nathan Given wrote:
> Hello All,
>
> I am trying to randomly change the background image of my home page
> but I can't seem to figure it out.
>
> Here is a snippet of my css
>
> ...
> BODY {background:transparent url(../images/homepagebg3.jpg) no-repeat
;
> font:normal 90% Arial, Helvetica, sans-serif; color:#263158;}
> ...
>
> Here is my javascript that I am trying to use to change my background
> image....
>
>
> <link type="text/css" href="css/main.css" media="screen"
> rel="stylesheet" />
> <link type="text/css" href="css/imagetitles.css" media="screen"
> rel="stylesheet" />
> <script language="javascript" type="text/javascript">
>
> images = new Array(3);
> images[0] = 'background:transparent url(../images/homepagebg3.jpg)
> no-repeat; font:normal 90% Arial, Helvetica, sans-serif;
> color:#263158;';
> images[1] = 'background:transparent url(../images/homepagebg1.jpg)
> no-repeat; font:normal 90% Arial, Helvetica, sans-serif;
> color:#263158;';
> images[2] = 'background:transparent url(../images/homepagebg2.jpg)
> no-repeat; font:normal 90% Arial, Helvetica, sans-serif;
> color:#263158;';
>
> index = Math.floor(Math.random() * images.length);
>
>
> document.getElementsByTagName("BODY")[0].style.background =
> images[index];
>
>
> </script>
>
>
> Here is the error from the firefox javascript console:
> Error: document.getElementsByTagName("BODY")[0] has no properties.
>
> Any ideas? How can I randomly change my background image?
>
> Thanks!
> --
> Nathan
You can't assign this in the CSS way since it is javascript and not CSS.
In this document there appears to be no javascript property for this
(don't know if they are right):
http://www.comptechdoc.org/independ.../javastyle.html
A way to achieve this is to make two classes in CSS and assign a new
class to the object.
You can see how you can assign a class using javascript in my tabular
navigation example at: http://www.top100nederland.net/test/tabjes.htm
regards,
Roderik
--
http://www.archytas.nl/
webdesign, internet applicaties, internetgestuurde elektronica
|
|
|
| [
Post Follow-Up to this message ]
|
|
|
|
|
 |
|
|
 |
| All times are GMT. The time now is 04:34 AM. |
 |
|
|
|
|
|  |
|