Click to See Complete Forum and Search --> : Random positioning of images
BritMiss
08-01-2003, 02:30 PM
I am trying to develop a web page which will utilize randomly placed images.
After an absence from the cyberworld of more than ten years, I am trying to pick up the threads of Javascript after previous experience with AWK but the whole deal with layers eludes me. Can anybody help?
:confused:
Something on these lines I think
<script>
myimg=new Array("pic1.jpg","pic2.jpg","pic3.jpg","pic4.jpg")
newImg=new Array() // create a new array
next_image=0
function showme(){
for(i=0;i<myimg.length;i++){
newImg[i] = new Image() // create a new image object for each image
newImg[i].src =myimg[i] // assign src to new image object
}
next_pic=parseInt(Math.random()*myimg.length)
document.showpic.src=myimg[next_pic]
Width=document.body.clientWidth-newImg[next_image].width
Height=document.body.clientHeight-newImg[next_image].height
posx=parseInt(Math.random()*Width)
posy=parseInt(Math.random()*Height)
document.getElementById("display").style.top=posy
document.getElementById("display").style.left=posx
}
</script>
<BODY onload="showme()">
<img id="display" name="showpic" src="pic1.jpg" width="100px" height="100px" style="position:absolute">
BritMiss
08-02-2003, 06:59 AM
Mr J, please accept my thanks for your generous help.
Can I ask you to clarify please?
Is the document.body.clientWidth object built into Javascript as a pre-existing object, or is it defined when the script compiles/executes?
The same query applies to the object document.getElementById
Once again, let me thank you for your help (and your patience)
:)
I am not very good at explaining things but here goes.
clientWidth is a property of the window object and is defined when the script executes
document.getElementById("id") references an object within the document
Phew ..... short but sweet