PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [Java-Script] Zufällige Bilderwahl


ich.com.sie.net
2006-05-03, 13:04:37
Hab ne kleine Frage und zwar will ich, dass das Logo bei jedem Reload ein neues ist. Die Auswahl würde ich so auf 3 oder 4 beschränken...

Ich hab es schonmal programmiert, ist aber schon Ewigkeiten her. Wäre cool, wenn mir jemand auf die Sprünge helfen könnte...

ich.com.sie.net
2006-05-03, 13:17:33
Ich hatte gerade einen Gedankenblitz... Ich poste mal die Lösung, damit der Thread net ganz nutzlos ist:

imageArray = new Array();
current = "";
function load_img(name_src)
{
if(document.images) {
var temp = imageArray[name_src];
if(! temp) {
temp = new Image();
temp.src = name_src;
imageArray[name_src] = temp;
}

return temp;
}
}
function replace_img(name, name_src)
{
if(document.images) {
if(name != current) {
document[name].src = load_img(name_src).src;
}
}
}


var theImages = new Array()
theImages[0] = 'strip_1.jpg'
theImages[1] = 'strip_2.jpg'
theImages[2] = 'strip_3.jpg'
theImages[3] = 'strip_4.jpg'
theImages[4] = 'strip_5.jpg'



var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

Mike1
2006-05-03, 14:26:01
auf java24 gibt´s auch so eins