DOM:event.relatedTarget
z Mozilla Developer Center, polskiego centrum programistów Mozilli.
Spis treści |
[edytuj] Podsumowanie
Wskazuje na drugi cel zdarzenia.
[edytuj] Składnia
eventTarget = event.relatedTarget
[edytuj] Parametry
eventTargetto referencja do dodatkowego celu zdarzenia (obiektuEventTarget).
[edytuj] Przykład
var rel = event.relatedTarget;
// dump("LEAVING " + (rel ? rel.localName : "null") + "\n");
// relatedTarget is null when the titletip is first shown:
// a mouseout event fires because the mouse is exiting
// the main window and entering the titletip "window".
// relatedTarget is also null when the mouse exits the main
// window completely, so count how many times relatedTarget
// was null after titletip is first shown and hide popup
// the 2nd time
if (!rel) {
++this._mouseOutCount;
if (this._mouseOutCount > 1)
this.hidePopup();
return;
}
// find out if the node we are entering is one of our
// anonymous children
while (rel) {
if (rel == this)
break;
rel.parentNode;
}
// if the entered node is not a descendant of ours, hide
// the tooltip
if (rel != this && this._isMouseOver) {
this.hidePopup();
}
[edytuj] Uwagi
Za specyfikacją W3C: "Obecnie ten atrybuty używany jest przy zdarzeniu mouseover, gdzie kieruje do EventTarget, jaki opuściło urządzenie wskazujące oraz przy zdarzeniu mouseout, gdzie kieruje do EventTarget, w który weszło urządzenie wskazujące."
Powyzszy przykład jest typowy - właściwość relatedTarget używana jest by znaleźć, jeśli jest związany z tym zdarzeniem, kolejny element. Zdarzenia takie jak najechanie myszą (mouseover) są powiązane z konkretnym elementem docelowym, ale mogą też angażować drugi cel, jak np. element opuszczany przez mysz w momencie, gdy najechania na główny cel.