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" />
- fl0's blog
- 664 reads
Recent blog posts
- Convert mov, mp4, avi, flv to ogv | ffmpeg2theora
- Stop Disabling SELinux! | Drupal and SELinux, Drupal doesn't send mails [SOLVED]
- Blender 2.59 + iCub SIM + Kinect = Movement Imitation
- Blender 2.59 + Kinect = Controlling Robot Arms in Game Engine
- Virtual (robot) Flobi - Motion Capture Playback Demo
- LimeSurvey | Default Password Change | Redirect to login page [SOLVED]
- Lighttpd | Can't have more connections than fds/2: 1024
- Warp1337 Theme for you!
- OpenNI Java Wrapper Test | Ubuntu 11.10
- Web history with Screenshots and stuff | Web archive
What is Flattr ? Flattr is the worlds first social micro-payment system The idea had already been initiated in 2007, but the first release was in 2010 due to typical geeky laziness. Flattr was founded to help people share money, not just content. https://flattr.com/about

















Comments
Post new comment