HTML / Javascript: X, Y-Koordinaten des Kreiselements erhalten

394
Steve G.

Ich brauche die X- und Y-Koordinaten eines HTML-Kreiselements in Javascript. Hier ist mein HTML-Code:

 <svg id="hotspot_canvas" name="hotspot_canvas" class="hotspot" width="800" height="1570.66666667" style="background-image: url('images/characters/fullbody/1.jpg'); background-size: 800px 1570.66666667px;"> <circle class="hotspot" id="hotspot0" name="hotspot0" cx="300" cy="75" r="50" href="javascript:void(0);" onclick="MovePopup('0', 200, 200);" onmouseover="MovePopup('0', 200, 200);" onmouseout="MovePopup('0', 200, -1000)" alt="" /> </svg> 

In meiner MovePopup-Javascript-Subroutine habe ich diesen Code:

function MovePopup(id, xcoord, ycoord) { var hotspot = document.getElementById('hotspot' + id); window.alert('Hotspot is ' + hotspot.style.left + ' pixels from the left of the window'); } 

Was ich brauche, ist die Anzahl der Pixel von der linken Seite des gesamten Fensters (nicht nur des SVG-Elements), aber alles, was ich versuche, gibt mir entweder "undefined" oder nichts. Weiß jemand, was ich falsch mache? Vielen Dank!

0

0 Antworten auf die Frage