Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: buttons to change BG


Message #1 by sdanckaarts@h... on Mon, 18 Sep 2000 17:56:10 +0100
As you'll have gathered, Javascript isn't my forte, but I really couldn't
find anything on the web that really did what you were asking for. The
nearest I came was this example:
http://javascript.internet.com/bgeffects/background-changer.html

Which I adapted to suit, using buttons. In the original example, you can
see what steps you'd need to take to trap-out browsers for which the
script won't work and the basic principles behind creating a list of
images that can be sawpped around.

Ironically, the one method for which Netscape's Communicator 4 could have
done that same thing - the Layer object - wasn't accepted by the W3C...
which is a shame, since it was really quite a useful object.

HTH
Daniel Walker

> Argh, I sent the wrong code. I was messing around writing it, editing it
> and running it and must have sent a half-done copy...
> 
> Here, try this:
> 
>  <SCRIPT LANGUAGE="JavaScript">
>  
>  <!--
>  image_directory = "plaatjes/";
>  Image1 = new Image();  Image1.src = image_directory + "velvet.jpg";
>  Image2 = new Image();  Image2.src = image_directory + "geld.jpg";
>  
>  
>  function imagechange(imgName) {
>  document.body.background = eval(imgName + ".src");
>                                }
>  </script>
>  
>  <body background="plaatjes/velvet.jpg">
>  
>  <Form>
>  <Input type="button" value="New Image" onClick="imagechange('Image2');">
>  <Input type="button" value="Old Image" onClick="imagechange('Image1');">
>  </Form>
>  
> Hopefully, that'll work.
> I've defined both Image1 and Image2 the way I have because it allows you
> to change back and forth between them.
> 
>  HTH
>  Daniel Walker
>  Wrox Press

  Return to Index