View Full Version : text randimiser


buffyfan
07-06-2003, 01:27 PM
i got a text randimise from that javascript source and i was wondering how u can do it with images?

Shaneo
07-06-2003, 01:34 PM
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] =
'http://66.221.37.206/pictures/createASite/youngwomantattoo.jpg'
theImages[1] =
'http://66.221.37.206/pictures/createASite/womanlookingatheaven.jpg'
theImages[2] = 'http://66.221.37.206/pictures/createASite/wateronhead.jpg'
theImages[3] = 'http://66.221.37.206/pictures/createASite/manpraying.jpg'
theImages[4] = 'http://66.221.37.206/pictures/createASite/indian.jpg'
theImages[5] = 'http://66.221.37.206/pictures/createASite/closeupman.jpg'
theImages[6] = 'http://66.221.37.206/pictures/createASite/closedeyes.jpg'
theImages[7] = 'http://66.221.37.206/pictures/createASite/bigblackman.jpg'
theImages[8] = 'http://66.221.37.206/pictures/createASite/baby.jpg'
theImages[9] = 'http://66.221.37.206/pictures/createASite/asianman.jpg'


// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img border="1" src="'+theImages[whichImage]+'">');
}

// End -->
</script>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

In your Template, simply insert this code to call the script:

>>>>>>>>>>>>>>>>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
showImage();
// End -->
</script>
Is that what u were after?

buffyfan
07-06-2003, 01:37 PM
thank you very much :D

do i add this script after the </head> tag or the <head> tag?

buffyfan
07-06-2003, 01:47 PM
either way it doesn't work :(

Shaneo
07-06-2003, 01:52 PM
How about..

<script language="Javascript">
<!--

var currentdate = 0
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '

}
}

image = new StringArray(10)
image[0] = '0.gif'
image[1] = '1.gif'
image[2] = '2.gif'
image[3] = '3.gif'
image[4] = '4.gif'
image[5] = '5.gif'
image[6] = '6.gif'
image[7] = '7.gif'
image[8] = '8.gif'
image[9] = '9.gif'

var ran = 60/image.length

function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}

document.write("<img src='" +ranimage()+ "'>")

//-->
</script>

buffyfan
07-06-2003, 02:18 PM
it did but how can i decide the width and height of my image and where it is going on the page?

Shaneo
07-06-2003, 02:21 PM
Change this line

document.write("<img src='" +ranimage()+ "'>")

to

document.write("<img src='" +ranimage()+ " width="??" height="??"'>")

And then put the whole code where ever u want it on your page as you would a normal image..

buffyfan
07-06-2003, 02:24 PM
i usually use the pixel code to decide where to put my images . how can i do that with this code AND still decide the width and height?

can it be done . I hope so :(

Stormx
07-06-2003, 02:25 PM
If you want to edit the width or height, find the bit where it says

document.write("<img src='" +ranimage()+ "'>")

and replace it with

document.write("<img src='" +ranimage()+ "' height='yourheight' width='yourwidth'>")

If you want to decide where the image is then either post the code where the image is, or define the image as a function.

put this in the head:


<script language="Javascript">
<!--
function randomimage() {
var currentdate = 0
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '

}
}

image = new StringArray(10)
image[0] = '0.gif'
image[1] = '1.gif'
image[2] = '2.gif'
image[3] = '3.gif'
image[4] = '4.gif'
image[5] = '5.gif'
image[6] = '6.gif'
image[7] = '7.gif'
image[8] = '8.gif'
image[9] = '9.gif'

var ran = 60/image.length

function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}

document.write("<img src='" +ranimage()+ "'>")
}
//-->
</script>

and then call the image from this code. You can use the following code to call the image as many times as you like


<script language="Javascript">
<!--
randomimage()
//-->
</script>

buffyfan
07-06-2003, 02:38 PM
i don't get it.


how do i decide where it is using pixels?

Stormx
07-06-2003, 02:40 PM
Any chance you can explain what u mean by that?

buffyfan
07-06-2003, 02:52 PM
well when i want to put an image on my page i use


<img style="position:absolute; top:25px; left:800px; width:150px;
height:150px" src="2.JPG">
and I want to know how to use that in the code for the "image randimiser"

kicker91
07-06-2003, 04:30 PM
Originally posted by Stormx
If you want to edit the width or height, find the bit where it says

document.write("<img src='" +ranimage()+ "'>")

and replace it with

document.write("<img src='" +ranimage()+ "' height='yourheight' width='yourwidth'>")

If you want to decide where the image is then either post the code where the image is, or define the image as a function.

put this in the head:


<script language="Javascript">
<!--
function randomimage() {
var currentdate = 0
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '

}
}

image = new StringArray(10)
image[0] = '0.gif'
image[1] = '1.gif'
image[2] = '2.gif'
image[3] = '3.gif'
image[4] = '4.gif'
image[5] = '5.gif'
image[6] = '6.gif'
image[7] = '7.gif'
image[8] = '8.gif'
image[9] = '9.gif'

var ran = 60/image.length

function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}

document.write("<img src='" +ranimage()+ "'>")
}
//-->
</script>

and then call the image from this code. You can use the following code to call the image as many times as you like


<script language="Javascript">
<!--
randomimage()
//-->
</script>


where it says document.write("<img src='" +ranimage()+ "'>"), replace it with document.write("<img src='" +ranimage()+ "' height="#" width="#">")

buffyfan
07-06-2003, 04:33 PM
u just quoted the person above?
why?

p.s it doesn't work!

kicker91
07-06-2003, 09:15 PM
i quoted stormx because his code was right, you just didnt add height="bla bla bla... and i don't understand why its not working.