Stefan D.: Ich find den Fehler nicht....

Hi!

Das ist mein 2. Javascript, es soll nur unter Internet Explorer funktionieren (Netscape steht mir nicht zur Verfügung..)

Der Iexplorer meldet, daß ihm etwas an document.all.Texta.style.left nicht gefällt..

Es soll folgendes werden: Wie bei einem Bildschirmschoner soll eine Schrift über den Bildschirm wandern und von jeder Ecke abprallen... (vorerst immer auf der selben Bahn...

Über das erste document.all... kommt er anscheinend drüber...
nur das zweite schafft er nicht (habs ausprobiert, in dem ich die beiden vertauscht hab...)

Kann mir wer von Euch helfen? Vielen Dank!

mfg
Stefan

<HTML>
<head>
<title>Servaaaaaaaaaaaaaaaaaaaaaas</title>
<script language="Javascript">
<!--
var MaxX=window.innerWidth;
var MaxY=window.innerHeight;
var Xpos=MaxX/2;
var Ypos=0;
var Direction=0;
var Dx=MaxX/500;
var Dy=MaxY/500;
var Speed=10;

function Move()
{
if ((Direction==0) && (Xpos>=0)) {Xpos-=Dx;Ypos+=Dy;}
if ((Direction==1) && (Ypos<=MaxY)) {Xpos+=Dx;Ypos+=Dy;}
if ((Direction==2) && (Xpos<=MaxX)) {Xpos+=Dx;Ypos-=Dy;}
if ((Direction==3) && (Ypos>=0)) {Xpos-=Dx;Ypos-=Dy;}
if ((Direction==0) && (Xpos==0)) Direction=1;
if ((Direction==1) && (Ypos==MaxY)) Direction=2;
if ((Direction==2) && (Xpos==MaxX)) Direction=3;
if ((Direction==3) && (Ypos==0)) Direction=0;
SetText();
}

function SetText()
{
document.all.Texta.style.top = Ypos;
document.all.Texta.style.left = Xpos;
window.setTimeout('Move()', Speed);
}

//-->
</script>

</head>
<body bgcolor="#000000" text="#FFFFFF" onLoad="window.setTimeout('Move()', Speed)">
<h2 id="Texta" style="position:absolute; top:0px; left:100px;
font-style:italic; font-family:Arial; text-decoration:underline">
Bildschirmschoner
</h2>
</body>
</HTML>

  1. Hi,

    Das ist mein 2. Javascript, es soll nur unter Internet Explorer funktionieren (Netscape steht mir nicht zur Verfügung..)

    Der Iexplorer meldet, daß ihm etwas an document.all.Texta.style.left nicht gefällt..

    um sowas zu debuggen ist es immer ganz nützlich, die variable z.b. über alert() auszugeben: in deinem falle war sie NaN (not a number), was darauf hindeutet, daß etwas mit dem ausgangswert nicht stimmt (in diesem fall liegt es an offsetWidth und offsetHeight, die gibt's nämlich nur unter Netscape).
    Auch solltest du dich nicht auf das <H2>-tag beziehen sondern alles hübsch in ein <DIV> oder <SPAN> setzen.

    So sollte es gehen:

    <HTML>
    <head>
    <title>Servaaaaaaaaaaaaaaaaaaaaaas</title>
    <script language="Javascript">
    <!--
    var MaxX, MaxY, xpos, ypos, Direction, Dx, Dy, Speed;

    function init() {
    MaxX= document.body.offsetWidth;
    MaxY= document.body.offsetHeight;
    Xpos=MaxX/2;
    Ypos=0;
    Direction=0;
    Dx=MaxX/500;
    Dy=MaxY/500;
    Speed=10;
    }

    function Move()
    {
    if ((Direction==0) && (Xpos>=0)) {Xpos-=Dx;Ypos+=Dy;}
    if ((Direction==1) && (Ypos<=MaxY)) {Xpos+=Dx;Ypos+=Dy;}
    if ((Direction==2) && (Xpos<=MaxX)) {Xpos+=Dx;Ypos-=Dy;}
    if ((Direction==3) && (Ypos>=0)) {Xpos-=Dx;Ypos-=Dy;}
    if ((Direction==0) && (Xpos==0)) Direction=1;
    if ((Direction==1) && (Ypos==MaxY)) Direction=2;
    if ((Direction==2) && (Xpos==MaxX)) Direction=3;
    if ((Direction==3) && (Ypos==0)) Direction=0;
    SetText();
    }

    function SetText()
    {
    document.all.Texta.style.top = Ypos;
    document.all.Texta.style.left = Xpos;
    window.setTimeout('Move()', Speed);
    }

    //-->
    </script>

    </head>
    <body bgcolor="#000000" text="#FFFFFF" onLoad="init();window.setTimeout('Move()', Speed)">
    <div id="Texta" style="position:absolute; top:0px; left:100px;">
    <h2 style="font-style:italic; font-family:Arial; text-decoration:underline">
    Bildschirmschoner
    </h2>
    </div>
    </body>
    </HTML>

    bis denndann...
    /*,*/
    Wowbagger