getElementById fehler in mozilla xhtml 1.0
marillchen
- javascript
0 Joachim
hallo!
ich hab hier einen scroller, und zwar den von http://www.dhtmlshock.com/scrollers/APScrollableArea/default.asp
leicht verändert (ohne browserabfrage) hier der code:
/*Scroller*/
var speed=30;
var loop, timer;
var initialised;
function InitialiseScrollableArea(){
objContainer=new ConstructObject('divContainer')
objScroller=new ConstructObject('divContent','divContainer')
objScroller.MoveArea(0,0)
initialised=true;
}
function ConstructObject(obj,nest){
nest=(!nest) ? '':'document.'+nest+'.'
this.el=document.getElementById(obj);
this.css=document.getElementById(obj).style;
this.scrollHeight=this.el.offsetHeight
this.clipHeight=this.el.offsetHeight
this.up=MoveAreaUp;this.down=MoveAreaDown;
this.MoveArea=MoveArea; this.x; this.y;
this.obj = obj + "Object"
eval(this.obj + "=this")
return this
}
function MoveArea(x,y){
this.x=x;this.y=y
this.css.left=this.x
this.css.top=this.y
}
function MoveAreaDown(move){
if(this.y>-this.scrollHeight+objContainer.clipHeight){
this.MoveArea(0,this.y-move)
if(loop) setTimeout(this.obj+".down("+move+")",speed)
}
}
function MoveAreaUp(move){
if(this.y<0){
this.MoveArea(0,this.y-move)
if(loop) setTimeout(this.obj+".up("+move+")",speed)
}
}
function PerformScroll(speed){
if(initialised){
loop=true;
if(speed>0) objScroller.down(speed)
else objScroller.up(speed)
}
}
function CeaseScroll(){
loop=false
if(timer) clearTimeout(timer)
}
------
in der html-datei wird das ganze dann so aufgerufen:
<body onload="InitialiseScrollableArea()">
...
<div id="divUpControl" style="top:112px;">
<a href="#" onmouseover="PerformScroll(-2)" onmouseout="CeaseScroll()"><img src="pfeil.gif" alt="up" /></a>
</div>
<div id="divContainer">
<div id="divContent">blablabla
</div>
</div>
mein problem: der scroller funktioniert zwar in ie6, opera 7, nicht aber in mozilla 1.4. und zwar nur dann nicht, wenn ich eine DTD angebe (xhtml 1.0 transitional). im quirks-mode läuft der scroller in allen drei browsern. die vorgabe ist aber leider, dass die seite xhtml 1.0 transitional sein soll.
mozillas javascript-console spuckt auch einen fehler aus und zwar:
Fehler: document.getElementById(obj) has no properties
Quelldatei: http://www.xxx.org/qu/javascript.js
Zeile: 17
das bezieht sich auf die zeile
this.css=document.getElementById(obj).style;
aus der function ConstructObject
was läuft hier falsch? meine javascript-künste reichen leider nicht aus...
lg,
marillchen
Hi,
this.css.left=this.x
this.css.top=this.y
Wenn Du nicht im Quirks Modus bist verlangt Mozilla eine Einheit:
this.css.top=this.y + (document.documentElement? "px" : "");
Gruesse Joachim