Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Random Image Generator + Address? (https://novahq.net/forum/showthread.php?t=45572)

EDGE 12-09-2010 02:32 AM

Random Image Generator + Address?
 
So, i want to know if anyone can modify this javascript for me to make the random images appear as clickable links.

Any help is appreciated.

Code:

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

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>


atholon 12-09-2010 08:04 AM

Code:

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

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href="'+myimages[ry]+'"><img src="'+myimages[ry]+'" border=0></a>')
}

//-->
</script>


.Simon. 12-09-2010 09:03 AM

Assuming you want them to link to the images?

atholon 12-09-2010 10:28 AM

Yeah, what I posted assumes that. You'd need to link an array of addresses otherwise.

EDGE 12-09-2010 02:14 PM

Quote:

Originally Posted by atholon (Post 370100)
Yeah, what I posted assumes that. You'd need to link an array of addresses otherwise.

No, actually reading my post I see that I wasn't clear with what I wanted at all lol. It was 5am, sorry, I was tired as hell.

I want the images to link to an outside like, like a forum post or something. So say I want the image to link to www.xoxide.com.

atholon 12-09-2010 03:32 PM

Yeah you'd just create another array and match the indexes;

Code:

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

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var imageLinks = new Array();
imageLinks[1]="www.google.com";
imageLinks[2]="www.blackzone.com";
imageLinks[3]="www.somethingstupid.com";
imageLinks[4]="www.ifailedsquared.com";
imageLinks[5]="www.blah.com";
imageLinks[6]="www.shiz.com";


var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href="'+imageLinks[ry]+'"><img src="'+myimages[ry]+'" border=0></a>')
}

//-->
</script>


EDGE 12-09-2010 03:58 PM

Sweet! Thank you, kind sir!

atholon 12-09-2010 04:00 PM

Np :)

EDGE 12-09-2010 04:17 PM

I have another question ath. Do you know of any scripts that show scrolling images, like the news image on this site - www.worldofwarcraft.com ? I'm not too sure what the script it called nor where to find one.

atholon 12-09-2010 05:56 PM

Ah, like a slideshow?

If that's what you're talking about then yeah, there's one called jcycle. It is way easy to use and it uses the jquery library. This is their site: http://jquery.malsup.com/cycle/
There might be a better one but that's the one I am using right now.

atholon 12-09-2010 06:05 PM

BTW, if you want to use jCycle I'd look at the pager functionality and the other advanced options.

EDGE 12-09-2010 06:27 PM

Thanks, bro. It works perfectly!

atholon 12-09-2010 07:00 PM

:) glad it works for yah.

Scott 12-09-2010 08:00 PM

Why do your arrays not start at zero? This makes me sad. :(

atholon 12-09-2010 08:48 PM

Hehe, I was going to mention that but figured I wouldn't to avoid confusing people.

.Simon. 12-10-2010 05:56 AM

Quote:

Originally Posted by Scott (Post 370133)
Why do your arrays not start at zero? This makes me sad. :(

Hah, you can have a big Like.


All times are GMT -5. The time now is 08:13 PM.

Powered by vBulletin®