Det her kode vil virke:
var width=700;
var height=350;
var pause=3000;
var fade=100;
var fadeimages=new Array();
fadeimages[0]="test1.bmp";
fadeimages[1]="test2.bmp";
fadeimages[2]="test3.bmp";
fadeimages[3]="test4.bmp";
fadeimages[4]="test5.bmp";
function $(element)
{
if (typeof element == 'string')
{
var element = (document.getElementById ? document.getElementById(element) : (document.all ? document.all[element] : (document.layers ? document.layers[element] : null)));
}
return element;
}
function slideShow(hojde,bredde,pause,fade,billeder,id)
{
if(!$(id)) return false;
this.hojde = hojde;
this.bredde = bredde;
this.pause = pause;
this.fade = fade;
this.billeder = billeder;
this.id = id;
this.current = 0;
this.canvas = 0;
this.preLoad();
}
slideShow.prototype = {
preLoad: function()
{
this.preloadedimages=new Array()
for (p=0;p<this.billeder.length;p++)
{
this.preloadedimages[p]=new Image()
this.preloadedimages[p].src=this.billeder[p]
}
},
fadePic: function()
{
if(this.curpos<100)
{
this.curpos+=10
if(this.tempobj.filters)
this.tempobj.filters.alpha.opacity=this.curpos;
else if(this.tempobj.style.opacity)
this.tempobj.style.MozOpacity=this.curpos/100;
}
else
{
clearInterval(this.dropslide);
this.tempobj=$(this.id+this.canvas);
this.current=(this.current<=this.billeder.length)? this.current+1 : 0;
this.tempobj.innerHTML='<img src="'+this.billeder[this.current]+'">';
t=this;
setTimeout("t.rotateImage()",this.pause);
}
},
rotateImage: function()
{
t=this;
this.resetIt();
this.tempobj=$(this.id+this.canvas);
this.tempobj.style.zIndex++;
this.dropslide=setInterval("t.fadePic()",this.fade);
this.canvas=(this.canvas=="0")? "1" : "0";
},
resetIt: function()
{
this.curpos=10;
var crossobj=$(this.id+this.canvas)
if (crossobj.filters)
crossobj.filters.alpha.opacity=this.curpos
else if (crossobj.style.MozOpacity)
crossobj.style.opacity=this.curpos/100
},
start: function()
{
$(this.id).innerHTML = '<div style="width:'+this.bredde+';height:'+this.hojde+';overflow:hidden">'+
'<div id="'+this.id+'canvas0" style="position:absolute;width:'+this.bredde+';height:'+this.hojde+';left:0;top:0;filter:alpha(opacity=10);opacity:0.1;">'+
'<img src="'+this.billeder[this.current]+'"></div>'+
'<div id="'+this.id+'canvas1" style="position:absolute;width:'+this.bredde+';height:'+this.hojde+';left:0;top:0;filter:alpha(opacity=10);opacity:0.1;"></div></div>';
this.id+='canvas';
this.rotateImage();
}
}
window.onload=function(){
test = new slideShow(height,width,pause,fade,fadeimages,"dit id på elementet");
test.start();
}
Indlæg senest redigeret d. 11.03.2008 20:11 af Bruger #11596