Look into offsetTop and offsetLeft, seeing as these will be absolutely
positioned elements.  If these elements are inside other elements (in other
words, their parent Element is NOT the body), this will work:

==========================================
  var objItem = document.getElementById("originalElHere")
  var objParent = null
  var intX = 0
  var intY = 0
  do
   { // Walk up our document tree until we find the body
    // and add the distance from the parent to our counter.
    intX += objItem.offsetLeft
    intY += objItem.offsetTop
    objParent = objItem.offsetParent.tagName
    objItem = objItem.offsetParent
   }
  while(objParent != 'BODY')

 alert("Left offset: " + intX + " AND Top offset: " + intY)
==========================================

Just throw that into a function and pass in the ID of the element. Then,
replace the "originalElHere" with the name of the element you're looking
for.

You'll have to figure out a way to return it yourself, and I suggest an
array that holds both the x and y.  Return NULLS if you're unable to
locate the element.

Chris Tifer


----- Original Message -----
From: "M. H. K." <[EMAIL PROTECTED]>
To: "ActiveServerPages" <[EMAIL PROTECTED]>
Sent: Thursday, October 10, 2002 4:32 PM
Subject: OT : Javascript list server like this one.


> Anyone to recommend a good one ?
> Thanks.
>
> Or those who might help me out with the following goal, I appreciate it.
>
> I want to show thumbnails of x number of images on the screen allowing
> user the drag them on the page to put in an order. Based on the top Y
> coordinate of the image, I am going to deifne the order and create a slide
> show of the larger versions of those thumbnails.
>
> At the end of this mail, I attached the code allowing the dragging of some
> images on a page.
>
>
> My goal is to create a sort button on the page that would cycle thru each
> image and tell me the x,y coordinates of each of them.
>
> How do you tell the XY cordinates of an image on the page ?
> Thanks.
>
>
> <html>
> <head>
> <script LANGUAGE="javascript">
> N = (document.all) ? 0 : 1;
> var ob;
> function MD(e) {
> if (N) {
> ob = document.layers[e.target.name];
> X=e.x;
> Y=e.y;
> return false;
> }
> else {
> ob = event.srcElement.parentElement.style;
> X=event.offsetX;
> Y=event.offsetY;
> }
> }
> function MM(e) {
> if (ob) {
> if (N) {
> ob.moveTo((e.pageX-X), (e.pageY-Y));
> }
> else {
> ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
> ob.pixelTop = event.clientY-Y + document.body.scrollTop;
> return false;
> }
> }
> }
> function MU() {
> ob = null;
> }
> if (N) {
> document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
> }
> document.onmousedown = MD;
> document.onmousemove = MM;
> document.onmouseup = MU;
> </script>
> </head>
>
> <body>
> <div id="s" style="position:absolute;left:50;top:300;">
> <img src=1.gif name="1">
> </div>
> <div id="d" style="position:absolute;left:50;top:350;">
> <img src=2.gif name="2">
> </div>
> <div id="c" style="position:absolute;left:100;top:300;">
> <img src=3.gif name="3">
> </div>
> <div id="h" style="position:absolute;left:100;top:350;">
> <img src=4.gif name="4">
> </div>
> </body>
> </html>
>
>
> ---
> You are currently subscribed to activeserverpages as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to
%%email.unsub%%


---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to