473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

position of an element relative to the page

i'm illiterate when it comes to javascript and browser issues, i'm
trying to code a small help module for my java app.i've went far
enough coding all the server side but i'm stuck with javascript now.

i'm trying to implement a tool tip behavior on a couple of input
element.
I just can't get to figure out the coordinates of the element in
question with respect to the page
especially when it is inside a scrollable container such as a DIV.
the tip has to be displayed right at the bottom left corner of the
element where the key is pressed therefor i would have to calculate
the coordinates of the element's current position on the page
regardless of how nested it is and taking into account the scrolled
amount of its parent container and ancestors each time.
i tried Peter-Paul Koch's findPos and tweeked it a bit as follows

function findPos(obj) {
if(obj==null)re turn [-1,-1];
var curleft =0;
var curTop=0;
if (obj.offsetPare nt) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParen t) {
curtop += obj.offsetTop-(obj.scrollTop? obj.scrollTop:0 );
curleft += onj.offsetLeft( obj.scrollLeft? obj.scrollLeft: 0);
}
}
return [curleft,curtop];

the problem is that offsetTop is not updated when i scroll.... i
always get a fixed value so that was not helping
thanks
o explanation ...

Oct 29 '07 #1
2 4110
steven acer wrote on 29 okt 2007 in comp.lang.javas cript:
i'm illiterate when it comes to javascript and browser issues, i'm
trying to code a small help module for my java app.i've went far
enough coding all the server side but i'm stuck with javascript now.

i'm trying to implement a tool tip behavior on a couple of input
element.
I just can't get to figure out the coordinates of the element in
question with respect to the page
especially when it is inside a scrollable container such as a DIV.
the tip has to be displayed right at the bottom left corner of the
element where the key is pressed therefor i would have to calculate
the coordinates of the element's current position on the page
regardless of how nested it is and taking into account the scrolled
amount of its parent container and ancestors each time.
i tried Peter-Paul Koch's findPos and tweeked it a bit as follows

function findPos(obj) {
if(obj==null)re turn [-1,-1];
var curleft =0;
var curTop=0;
if (obj.offsetPare nt) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParen t) {
obj == obj.offsetParen t

perhaps?

Not that I understand what you are after ;-)
curtop +=
obj.offsetTop-(obj.scrollTop? obj.scrollTop:0 );
curleft +=
onj.offsetLeft( obj.scrollLeft? obj.scrollLeft: 0);
}
}
return [curleft,curtop];

the problem is that offsetTop is not updated when i scroll.... i
always get a fixed value so that was not helping
thanks
o explanation ...



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 29 '07 #2
steven acer wrote:
the problem is that offsetTop is not updated when i scroll....
Of course it isn't. But scrollTop is.
i always get a fixed value so that was not helping
Posting with proper spelling would increase
your chances of getting helpful replies.

http://jibbering.com/faq/
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Oct 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11018
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 scroll/resize. Then the image "moves" on the screen but the animation doesn't. The net effect is that their relative positioning changes. I'd like to have it be that they would stay in the same relative position. I want to keep the image as an...
14
21925
by: Zenobia | last post by:
Hello folks, Is it possible to position an item within a <td> element? For instance see below. The table has multiple rows, one for each database record. Each row has 3 hrefs associated with it (for edit, delete and update). I want to position these 3 href items in the same columns, which would be posible if the span could be positioned - for instance on the extreme right of the td in which it is contained.
4
8275
by: boclair | last post by:
Is this a known problem with IE6? I have a provisional two column layout, the left menu column is positioned absolute. The contents column is positioned relative. The contents column has an image floated right. The placement is there in IE6 but not the image. It does not matter whether the DTD is strict or transitional
3
19779
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following test case element1 and element2 should be placed side by side inside a centered white container element: http://www.markusernst.ch/test.htm
6
6081
by: Gérard Talbot | last post by:
Hello fellow stylers, When trying this page http://www.gtalbot.org/BrowserBugsSection/PercentualRelativePositioning.html I get different rendered layouts with IE 6, IE 7 beta 2, Firefox 1.5.0.2 and Opera 9.0 build 8367. Firefox 1.5 and Opera 9 will just ignore the CSS declaration
6
6484
by: axlq | last post by:
I've spent most of the day struggling with what I thought would be a trivial problem. I have a hidden element that appears, outside of the normal flow, when the mouse hovers over an inline element. HOWEVER, I want the hidden element positioned at a location of my choosing relative to that inline element. Is this possible?
4
26489
by: vunet.us | last post by:
I have a DIV element. How can I find mouse position (top and left) inside of this DIV? <div onMouseMove="getPositions();" style="width:200px;height:100px"></div> function getPositions(ev){ ???????????????? }
4
29389
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 shows this could be done a containing element with "min-height: 100%;" and an absolute positioned element (div) inside, aligned to bottom ("position: absolute; bottom:0px")
10
3273
by: Mark | last post by:
According to my book on CSS, if you apply 'position: relative' to a block-level element, it will stay exactly where it is. However, you can then use top, left etc. to offset the element relative to its position. However, looking at other people's stylesheets, I often see 'position: relative' applied to elements but without the use of top, left etc., which makes me think using 'position: relative' has some other effect that my book has...
5
4390
Frinavale
by: Frinavale | last post by:
Hi! I'm attempting to display a <div> element on top of my page's content so that the user cannot interact with it while being prompted to answer a question. I have set this <div> to have a position:fixed style (have also tried position:absolute as well). On my page I have a button with a style of "top:50%; position:relative;" and this button is appearing on top of the <div> element that is supposed to be preventing user interaction. I...
0
8917
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9142
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.