Hi everybody!
I need a script, which calculates screen coordinates of given object (e.g. textbox or div). By "screen coordinates" I mean offset from upper left corner of the screen (not frame or browser window).
Thanks in advance.
11 5286
Use the screenX/screenY properties.
You won't be able to get that if the HTML is rendered itself. But if you have set the position, and left and top of the elements by CSS (or javascript), only then you would be able to retrieve the x and y coordinates as -
var x = parseInt(elementObj.style.left);
-
var y = parseInt(elementObj.style.top);
Use the screenX/screenY properties.
And that was a really old post! ... :D
And that was a really old post! ...:D
Must've been bored.
Like me
You won't be able to get that if the HTML is rendered itself. But if you have set the position, and left and top of the elements by CSS (or javascript), only then you would be able to retrieve the x and y coordinates as -
var x = parseInt(elementObj.style.left);
-
var y = parseInt(elementObj.style.top);
That would give you the x/y coordinates within the browser, not the screen
...and yes, it's an old post, but no-one answered it (poor thing!)
Must've been bored.
Like me
But you don't reply in your own threads... :-/
That would give you the x/y coordinates within the browser, not the screen
oh.. I see... good point..
So one can still calculate the browser's offset wrt the screen by doing - var offsetX = event.screenX - event.pageX; //(or clientX)
-
var offsetY = event.screenY - event.pageY; //(or clientY)
And then add that in x and y calculated above...
what say? :p
...and yes, it's an old post, but no-one answered it (poor thing!)
I hadn't joined by the time. :p
oh.. I see... good point..
So one can still calculate the browser's offset wrt the screen by doing - var offsetX = event.screenX - event.pageX; //(or clientX)
-
var offsetY = event.screenY - event.pageY; //(or clientY)
And then add that in x and y calculated above...
what say? :p
screenX and screenY should be enough, see link.
I hadn't joined by the time. :p
Neither had I ;)
screenX and screenY should be enough, see link.
But still, how would you tell what are the coordinates of a <div> element (for instance) wrt the screen? I'm not getting what you are trying to say.
This is what I understand from screenX and pageX:
But still, how would you tell what are the coordinates of a <div> element (for instance) wrt the screen? I'm not getting what you are trying to say.
I see now what you mean. Yes, screenX/Y would give the screen co-ordinates, pageX/Y the co-ordinates relative to the document. However, it's not supported in IE, so you'll have to use clientX/Y plus scrolling offset in IE to get the same value.
I see now what you mean. Yes, screenX/Y would give the screen co-ordinates, pageX/Y the co-ordinates relative to the document. However, it's not supported in IE, so you'll have to use clientX/Y plus scrolling offset in IE to get the same value.
I know its not an IE thing. But while having a logical conversation, we should keep IE out. :D
Of course it would need some fix as usual. :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MLH |
last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;100973
shows Function Screendump(). It is code that effectively does the
same thing as pressing SHIFT-PRTSCR on your keyboard. I am
trying...
|
by: phil cunningham |
last post by:
Hello,
I am looking for a good way to scale real objects on to the screen/printer
In our project, objects are created assuming the units are meters. For example, I may have a rectangluar shape...
|
by: Dan Sikorsky |
last post by:
How do you get the x,y pixel location of a textbox so that you can position
the Web Date Control popup nearby the associated textbox that will contain
the date selected by the Web Date Control?
...
|
by: ZorpiedoMan |
last post by:
Help... I need the screen coordinates of a control so I can place a pop
up form underneath it.
--Zorpy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in...
|
by: zoneal |
last post by:
OS: Win XP
Language: VB.net or C#
I have a program where I need to launch 2 separate instances of an App
called "Main.exe". Each instance will need to be piped to there own
video display. ...
|
by: steve |
last post by:
Hi All
I have textboxes within a TableLayoutpanel and I want to be able to position
an independant control adjacent to a selected textbox
This independent control allows selection of text to...
|
by: Peter Oliphant |
last post by:
I'm programming using MS VS VC++ 2008 Express (Beta 2) in /Cli pure mode.
I've found the Screen class. With it I can very easily get the count and all
the data on the various Screens attached to...
|
by: raylopez99 |
last post by:
keywords: logical coordinates, page coordinates, world coordinates,
device coordinates, physical coordinates, screen coordinates, client
coordinates. offset rectangle. WYSIWYG rubber rectangle...
|
by: raylopez99 |
last post by:
I have a logical drawing space much bigger than the viewport (the
screen) and I'd like to center the viewport (the screen) to be at the
center of the logical drawing space. After following the...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |