Einzelnen Beitrag anzeigen

Flare

Registriert seit: 26. Jan 2006
Ort: Leipzig
529 Beiträge
 
Delphi 7 Professional
 
#5

Re: [JS] Seltsames Phänomen

  Alt 7. Mai 2007, 12:59
Okay, ihr scheint mich nicht ganz verstanden zu haben, hoer nochmal der komplette Javascript-Code, der auch genau so klappt wie er klappen soll, nur stört mich Zeile 27. Aber wenn ich es so mache, wie es jeder Programmieren würde, klappt es nicht.

Es ist eine Funktionssammlung für Tooltips.

showtimeout und hidetimeout sind die Handles (wenn man das so nennen kann) von den 2 Timern zum zeigen und verschwinden des Tooltips.
Code:
<script language="JavaScript" type="text/javascript">
   wmtt = null;
   x = 0;
   y = 0;
   
   document.onmousemove = updateWMTT;
   
   function updateWMTT(e) {
      x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
      y = (document.all) ? window.event.y + document.body.scrollTop : e.pageY;
      if (wmtt != null) {
         wmtt.style.left = (x + 20) + "px";
         wmtt.style.top = (y + 20) + "px";
      }
   }
   
   function showWMTT(id, time) {
      if (time==0) {
         if (wmtt != null) {
            hideWMTT(0);
         }
         wmtt = document.getElementById(id);
         wmtt.style.display = "block";
         wmtt.style.left = (x + 20) + "px";
         wmtt.style.top = (y + 20) + "px";
      }else{
         id2 = id; // warum muss ich id an einer anderen Variable zuweisen bevor ich sie benutzen kann?
         showtimeout = window.setTimeout("showWMTT(id2, 0)", time); // hier steht id2 statt id
      }
   }
   
   function hideWMTT(time) {
      if (showtimeout) {
         window.clearTimeout(showtimeout);
      }
      if (time==0) {
         wmtt.style.display = "none";
         window.clearTimeout(hidetimeout);
      }else{
         hidetimeout = window.setTimeout("hideWMTT(0)", time);
      }
   }
</script>
<div class="tooltip" id="tip1">Und hier steht er</div><div onMouseOver="showWMTT('tip1', 500)" onMouseOut="hideWMTT(500)" style="display: inline;">Hier gibt es einen Tooltip</div>
Das hier klappt nicht, und ich weiß nicht warum
Code:
showtimeout = window.setTimeout("showWMTT(id, 0)", time);
Falls ihr noch Erklärungen zu allen einzelnen Variablen braucht, meldet euch


Flare
Willy Scheibel
  Mit Zitat antworten Zitat