Alex: Kann den Fehler im Farbübergangsscript nicht finden!

Ich hab einen Farbübergang in JS geschrieben und irgendwo ist da der Hund drin.

Schaut mal auf http://www.whf.at und fahrt mit der Maus über das Menü. Da ist irgendwo ein Fehler drinnen, weil wenn ihr nicht bis zum Ende der Animation wartet, sondern in das Nachbarfeld fahrt und dort dann auch gleich wieder raus, dann wird die Animation fortgesetzt.
Außerdem werden die Farbattribute nicht korrekt zurückgesetzt (wenn ich schon bei der farbe Hellrot war, dann fängt der Übergang im nächsten Feld bei Hellrot an und nicht ganz am Anfang)

Ich hab da einen Denkfehler im Script, weiß aber nicht wo...
Zu Demo-Zwecken hab ich das TimeOut nach oben geschaltet.

mfg
AleXP

  1. Hi,

    ich würd dir ja gerne mal helfen kann mir aber den Quelltext net anschaun! Also irgendwie muss ich den Code schon noch sehen bevor ich den Fehler suche und finde :)

    Gruß Christoph

  2. Da sind einige Fehler drin gewesen:

    // Copyright by Alexander Hofbauer

    var CellOver     = "#F3B269";
    var CellOut      = "#0C2A52";
    var CellOverText = "#000000";
    var CellOutText  = "#FFFFFF";
    var HoverColor   = "#AA6419";
    var NormalColor  = "#000000";

    var msg = new Array(
       '',
       "Hier geht es zurück zur Startseite",
       "Text1", "Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2",
       "Wie man die Firma Walter Hofbauer erreichen kann",
       "Irgendwas TEST TEST",
       "Text6",
       "Text7"
    );

    // Begin var for ColorFader
    var timeOut     = 50;
    var startColorR = 40;
    var startColorG = 05;
    var startColorB = 05;

    var incColorR   = 20;
    var incColorG   = 10;
    var incColorB   = 5;

    var maxColorR   = 240;   // 240
    var maxColorG   = 175;   // 175
    var maxColorB   = 105;   // 105
    // End var for ColorFader

    var newColorR = startColorR;
    var newColorG = startColorG;
    var newColorB = startColorB;
    var stopAnim = false;
    var newAnim = true;

    function HoverMenu (text, obj, color, textColor, format)
    {
      var style = obj.style;
      if (document.getElementById)
      {
          document.getElementById('LinkInfo').innerHTML = msg[text];
      }
      else if(document.all)
      {
          document.all['LinkInfo'].innerHTML = msg[text];
      }

    style.color = textColor;
      textDecoration = format;

    if (color == CellOut)
      {
         stopAnim = true;
         newAnim = true;
         newColorR = startColorR;
         newColorG = startColorG;
         newColorB = startColorB;
         style.backgroundColor = CellOut;
      }
      else
      {
         if (newAnim)
         {
            newColorR = startColorR;
            newColorG = startColorG;
            newColorB = startColorB;
            cellName = obj;
            stopAnim = false;
            newAnim = false;
            animColor();
         }
      }
    }

    var cellName = null;
    function animColor()
    {
      window.status = "ANIM";
      var obj = cellName;
      if(obj) style = obj.style;
      if (!stopAnim)
      {
          colorTest = '#' + Hex(maxColorR) + Hex(maxColorG) + Hex(maxColorB);
          if (colorTest == style.backgroundColor)
          {
             newColorR = startColorR;
             newColorG = startColorG;
             newColorB = startColorB;
             stopAnim = true;
             newAnim = true;
          }
          else
          {
             newColorR = (newColorR == maxColorR) ? maxColorR : newColorR + incColorR;
             newColorG = (newColorG == maxColorG) ? maxColorG : newColorG + incColorG;
             newColorB = (newColorB == maxColorB) ? maxColorB : newColorB + incColorB;
             style.backgroundColor = '#' + Hex(newColorR) + Hex(newColorG) + Hex(newColorB);
             setTimeout('animColor();',timeOut);
          }
      }
      else
      {
          newColorR = startColorR;
          newColorG = startColorG;
          newColorB = startColorB;
          stopAnim = false;
          newAnim = true;
      }
    }

    function hexConv(num)
      {
      if (num == 0) return("0"); if (num == 1) return("1"); if (num == 2) return("2"); if (num == 3) return("3");
      if (num == 4) return("4"); if (num == 5) return("5"); if (num == 6) return("6"); if (num == 7) return("7");
      if (num == 8) return("8"); if (num == 9) return("9");
      if (num == 10) return("a"); if (num == 11) return("b"); if (num == 12) return("c");
      if (num == 13) return("d"); if (num == 14) return("e"); if (num == 15) return("f");
      }

    function Hex(number_byte)
      {
      num1 = Math.floor(number_byte / 16);
      num2 = number_byte - (num1 * 16);
      num3 = hexConv(num1) + hexConv(num2);
      return(num3);
      }

    function LinkClick (resource)
      {
      parent.main.location.href = resource;
      }

    // Copyright by Alexander Hofbauer (Struppi)

    und der HTML Code:
            <td width="105" height="5" align="center" ID="Cell1" borderColor="#B8D2F0" class="Menu"
             onMouseOver="HoverMenu(1,this ,CellOver,CellOverText,'underline')"
                onMouseOut="HoverMenu(0,this,CellOut,CellOutText,'none')"><a href="Home.htm">HOME</A> </td>

    <td width="3" height="5" align="center" bgColor="#B8D2F0" borderColor="#B8D2F0" borderColorLight="#B8D2F0" borderColorDark="#B8D2F0" ID="CellSpace"></td>

    <td width="140" height="5" align="center" ID="Cell2" borderColor="#B8D2F0" class="Menu"
            onMouseOver="HoverMenu(2, this ,CellOver,CellOverText,'underline')"
                onMouseOut="HoverMenu(0, this ,CellOut,CellOutText,'none')"
                ><a href="home.htm">Firmengeschichte</A></td>

    Das was du gemacht hast, funktioniert nicht mal ansatzweise in alten Browser. D.H. es gehen noch nicht mal die Link, du solltest wenigstens das <A HREF=".."> drinlassen.

    Struppi.

    1. Ok. Danke. Das waren aber nur ein paar Schönheitsfehler.
      Den eigentlichen Fehler hat das NICHT ausgemerzt.

      Der Farbübergang ist immer noch fehlerhaft. Außerdem hab ich da irgendwo einen KLAMMER-Fehler drinnen.

      Solltet Ihr was ausbessern, dann bitte mit //kommentieren, damit ich die Stelle besser finden kann.

      mfg