Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Change image on site using Java or CSS?
Old 07-18-2006, 10:35 AM Change image on site using Java or CSS?
Granwalla's Avatar
Average Talker

Posts: 15
Trades: 0
Hi, all. I'm trying to find a script that will randomly choose an image from a pre-determined group of pictures each time someone visits a site. I know it should be simple to find, but I'm not having much luck. Right now, I have 2 images to flip between, will probably add more later. I can use CSS or Javascript - I'm not picky as long as it works and isn't super-complicated to implement.

Any help would be greatly, greatly appreciated.
__________________
Me: "Sir, do you have a firewall?"

EU: "Yeah, between the house and the garage . . ."
Granwalla is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-18-2006, 10:56 AM Re: Change image on site using Java or CSS?
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Like this:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
var baseUrl = "http://www.suzukicycles.com/images/ProductImages/colorVariations/500/";
var myImages = new Array("GSXR600K6_RedBlack_D31F1C.jpg","GSXR600K6_BlackGray_000000.jpg","GSXR600K6_SilverWhite_768594.jpg","GSXR600K6_aWhiteBlue_004C9F.jpg");

function setRandomImage() {
	var r = Math.floor(Math.random()*(myImages.length));
	document.getElementById("GSXR").src = baseUrl + myImages[r];
}

window.onload = setRandomImage;
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<p><img src="" alt="" border="0" id="GSXR" onclick="setRandomImage()"><br>Click image to randomize.</p>
	</body>

</html>
?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 07-18-2006, 11:04 AM Re: Change image on site using Java or CSS?
Granwalla's Avatar
Average Talker

Posts: 15
Trades: 0
That's great and I really appreciate your time.

However, is there a way that it just picks a new image each time a page is visited without having to click on the image itself to change it?

An example of what I mean is at http://www.jordanfashions.com. Each time you refresh the page, there is a new image. I am not a code queen, so when I looked through the source, I couldn't find where it showed the code for it.
__________________
Me: "Sir, do you have a firewall?"

EU: "Yeah, between the house and the garage . . ."
Granwalla is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 12:35 PM Re: Change image on site using Java or CSS?
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
The script does that:
Code:
 window.onload = setRandomImage;
I just added the click to show the effect. The sample you linked to does it using server-side code like PHP or ASP, not using JS.

Last edited by funkdaddu; 07-18-2006 at 12:38 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 07-18-2006, 12:40 PM Re: Change image on site using Java or CSS?
Granwalla's Avatar
Average Talker

Posts: 15
Trades: 0
Thanks so much!

*added to talkputation*
__________________
Me: "Sir, do you have a firewall?"

EU: "Yeah, between the house and the garage . . ."
Granwalla is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Change image on site using Java or CSS?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15038 seconds with 12 queries