RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

Alternating backgrounds?

Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Alternating backgrounds?

  #12  
Jul 28th, 2005
<html>
<script type="text/javascript">
	var images = new Array("http://homepages.ihug.co.nz/~jlittle/imgs/NZULtWt3rdOpen8.jpg", 
		"http://homepages.ihug.co.nz/~jlittle/imgs/OpenMensRace.jpg", 
		"http://homepages.ihug.co.nz/~jlittle/imgs/vic_snr_8_2003.jpg", 
		"http://homepages.ihug.co.nz/~jlittle/imgs/vic_8_2_2003.jpg");
	
	function randomImageSelector(){
		var imageNode = document.getElementById("randomImage");
		
		//var index = Math.floor(Math.random() * images.length);
		
		// getTime returns number of ms since 1/1/1970 - regardless of how you tell the time.
		// since my image set here is quite small, this doesn't really provide a much different
		// response than the random implementation.
		
		// to get a better result, you could try getSeconds or even getMinutes...
		// these return a number between 0-59 ... 
		var index = (new Date().getTime())%images.length;
		
		imageNode.src = images[index];
		imageNode.alt = images[index];
		
		document.getElementById("ms").innerHTML = index;
	}
	
	window.onload = function(){
		randomImageSelector();
	};
</script>

<body>

<img src="" id="randomImage"/>

<div id="ms"></div>

</body>
</html>
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:18 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC