morsa801tons
04-21-2005, 08:27 AM
Hi!
i've got two images (1 px transparent gif) and want to know distance in pixels between them... is it possible? Can i know image current screen position? (x,y)
Thanks!
scragar
04-21-2005, 08:57 AM
<script type="text/javascript"><!--
var n = document.getElementsByTagName("IMG");
var q = "";
q += "they are ";
var w = parseInt(n[1].style.top) - parseInt(n[0].style.top);
if(w < 0)
w = 0-w;
q += w + " pixels appart on the Y axis.\n";
q += "they are ";
var l = parseInt(n[1].style.left) - parseInt(n[0].style.left);
if(l < 0)
l = 0-l;
q += l + " pixels appart on the X axis.\n";
q += "they are ";
var n = Math.pow(w, 2) + Math.pow(l, 2);
n = Math.pow(n, 1/2);
q += n + " pixels appart using pythagarus.";
alert(q);
//-->
</script>