UHHH | JavaScript Random Image() TILED

Hmm...PHP / FLASH / AJAX ... there are a lot of website-tools which provide random image functions. If you ask google you'll get tons of more or less correctly written JavaScript code.

The problem is: Those functions just load ONE image at a time. What if you want a random set of tiled images? The answer is code it yourself. Approximately 15 lines of JavaScript.

Here's the result. Only images sets will be randomly loaded.


Here's the code:


  function randimg() {
	
  var zufall=Math.random()*(3-0)+0;	
  	
  zufall=Math.round(zufall);
  
  if (zufall == 0) 
  {
  document.getElementById('zufallsbild1').src="/images/A1s.png";
  document.getElementById('zufallsbild2').src="images/A2s.png";
  document.getElementById('zufallsbild3').src="/images/A3s.png";
  } 
  else if (zufall == 1) 
  {
  document.getElementById('zufallsbild1').src="/images/mix2A.jpg";
  document.getElementById('zufallsbild2').src="/images/mix2B.jpg";
  document.getElementById('zufallsbild3').src="/images/mix2C.jpg";
  } 
  else if (zufall == 2) 
  {
  document.getElementById('zufallsbild1').src="/images/mix4A.jpg";
  document.getElementById('zufallsbild2').src="/images/mix4B.jpg";
  document.getElementById('zufallsbild3').src="/images/mix4C.jpg";
  } 
  else 
  {
  document.getElementById('zufallsbild1').src="/images/mix3A.jpg";
  document.getElementById('zufallsbild2').src="/images/mix3B.jpg";
  document.getElementById('zufallsbild3').src="/images/mix3C.jpg";	
  }
  }

Add an onload tag to your body

<body onload="randimg()">

The target images

<img id="zufallsbild1" width="223" />
<img id="zufallsbild2" width="223" />
<img id="zufallsbild2" width="223" />

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.