View Full Version : createElement('div') in a random location

03-03-2005, 07:49 PM

I am looking to do the following for a netArt project and can't figure out if it is possible. My instructor suggested I post my question here.

The goal is to have a location on my webpage that if you click it, images of little cartoon children will pop up within the same browser window at random locations. I figured it had something to do with creating a new layer and placing an image within it but can't quite deciper if and how this is possible.

I assume it has something to do with createElement('div') but can find nothing on being able to place these layers randomly.

Is it possible? Is there a better way?

Thanks for any info provided,


03-05-2005, 05:51 AM
To place an element, set style properties ('position', 'left', and 'top').

To set left & top randomly, use a couple of Math object methods (floor, random).

To keep the element inside of the visible area, subtract element dimension properties (such as offsetWidth|offsetHeight from the body's dimensions), and use that in the equation...