Finding new coordinates of x and y for image(s)

D

DL

Hi,

Say, I have an image with id of "img1" currently at coordinates of
100,100, now, say, I have a way to move it to any other coordinates,
be it 210,340 or 520,310 or whatever other x,y, how could I find the
new coordinates of the "img1" object? And am I able to save it an
HTML file so that next time when I pull it up it would have the newest
coordinates?

Thanks in advance.
 
V

VK

Say, I have an image with id of "img1" currently at  coordinates of
100,100, now, say, I have a way to move it to any other coordinates,
be it 210,340 or 520,310 or whatever other x,y, how could I find the
new coordinates of the  "img1"  object?

How do you drag it? It is obviously some other script that must
monitor mouse relative and absolute coords in order to move the image.
So make it tell them to you on mouseup.
And am I able to save it an
HTML file so that next time when I pull it up it would have the newest
coordinates?

For client-side solution use cookies if enabled, see
https://developer.mozilla.org/en/DOM/document.cookie
http://www.jibbering.com/faq/#testCookie
 
D

DL

I could swear there was something about this in the FAQ, but I can't
find it at the moment. The FAQ notes page looks suspiciously empty.
If there really is nothing,
  <FAQENTRY>somebody qualified, please add it :)</FAQUENTRY>
because this is (more or less) frequently asked, and I'd be interested
in a stand-alone general solution myself.

Anyway, finding the position of an element on a page isn't as simple as
it sounds. It depends on various factors, like how the element is
positioned and styled; what its parent elements are, and what their
style settings are; whether your document is in quirks mode or not, etc.
I don't have a ready-to-go solution for all circumstances, because I
never needed one (I usually know my documents well enough to be able to
ignore most of the problems).

In your case, you probably already have a solution, because you managed
to move the element. Take a look at what that code is doing.

Generally speaking, if you want to know how far an element is from the
top of the document (=its y position), you look at its offsetTop
property. Then you look at the element's offsetParent element, and add
its offsetTop value, and so on, until there are no more offsetParents.
You'll have to take into account borders and margins, too. Getting the x
position is similar, except that you read the offsetLeft values.


It's possible, theoretically, in some circumstances, but very likely not
the solution you're looking for. Did you consider using cookies to store
the current position?

Thank you both, I'll dig further...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top