Hi Everyone!
I need to get the position coordinate (left and top)of a object (any object, lets say image) in browser window. The position should be with respect to browser window's size i.e we should take care the browser's size, scrolling etc. So the position will be variant if we resize the browser window. Please give me some idea.
I used -
document.getElementById("myImg").getBoundingClient Rect(). But not got proper position.
Also I used but didn't work. - while (element) {
-
coords.x += element.offsetLeft;
-
coords.y += element.offsetTop;
-
element = element.offsetParent;
-
}// returning coords
5 1882 gits 5,390
Expert Mod 4TB
you may have a look here ... and see whether that helps?
kind regards
Thanks gits!
But, the example mentioned be you finds the real position. If you resize the page and run the script again, it points to the correct new position of the element.
Actually I am looking to get the position w.r.to browser. Let say my object's actual position is (100,100). When I resize the browser or scroll, I should get current position (say 10,20), not actual position. Can you please tell me?
are you trying to get the object's coords on the screen or the object's coords in the browser?
you talk of resizing the browser is confusing, as that could leave either of the two coords noted above unchanged.
moving the browser window would affect the screen coords, but not the browser coords.
jumping ahead, to get the screen coords, you will have to add in the position of the browser relative to the screen.
are you trying to get the object's coords on the screen or the object's coords in the browser?
you talk of resizing the browser is confusing, as that could leave either of the two coords noted above unchanged.
moving the browser window would affect the screen coords, but not the browser coords.
jumping ahead, to get the screen coords, you will have to add in the position of the browser relative to the screen.
Yes, I wanted to find out the screen coords actually. Thanks!
Use screenX/screenY - cross-browser compatible too.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Kast |
last post by:
Here's my situation. I have a statically positioned table that has an image
in a cell. I also have some layers, defined by absolute-positioned DIVs for
some animation. Everything works until I...
|
by: Robster |
last post by:
I'd to postion a pop up windown to appear in a position relevtive to
the centre of the screen, rather than top=200, left=200.
Is there any way i can do this?
Alternatively i need a script that...
|
by: Danny |
last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as
well as Opera and IE6?
I'm struggling to understand how to capture mouse movement events with
Mozilla/Netscape/Firefox and...
|
by: Konrad Viltersten |
last post by:
Suppose you got a really long page and you'd like to enable
the user (supposedly, there's only one but if it's not to
difficult we could extend that to any number) not to have
to scroll to the...
|
by: Doc |
last post by:
I've read in a couple of different places including the archives of this
forum that html doesn't allow you to precisely dictate the position of an
image, but I found this command (again in the...
|
by: malcolm |
last post by:
I have a scrollable vb.net form with a web browser (axWebBrowser) instance on
it.
All is well until I try to change the left/top (and perhaps height/width) of
the web browser on the form. If...
|
by: rockdale.green |
last post by:
Hi,
I do not know where should I start to solve this problem.
I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the...
|
by: petermichaux |
last post by:
Hi,
It seems like determining element position in a web page is a difficult
task. In the position reporting source code I've looked at there are
special fixes for at least some versions of...
|
by: john |
last post by:
Hi to All,
I am new to html authoring, so sorry if my terminology is not correct or
exact.
I would like to position a footer div to the bottom of the browser window.
As I research in the web...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: 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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |