473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

cursor postion for DIV relative position - understanding clientX/Y and OffsetX/Y

I'm trying to understand this and don't get it...

I found some code that looks like it's going to work if I can make
sense of how to position the div.

The code displays a div with some data when I mouse over an element (A
column in an ASP.NET Gridview, but I suppose that's not important)

Everything works great, except I can't seem to position the div where I
want given scrolling.

pardon the comments and failed attempts.

the javascript:

<script language="javascript" type="text/javascript">
function ShowTooltip(L1,L2)
{
document.getElementById("L1").innerText=L1;
document.getElementById("L2").innerText=L2;
//x = event.clientX + document.body.scrollLeft;
y3 = event.clientY + document.body.scrollTop + 10;
y = event.y ;
yy = event.offsetY;
//x = event.clientX ;
//y = event.clientY ;
//y = event.clientY ;
status= y + ' ' + yy + ' ' +y3;
var Popup= document.getElementById("Popup")
Popup.style.display="block";
Popup.style.position="absolute";
Popup.style.left = 230;
//Popup.style.top = y + 650
Popup.style.top = y;
Popup.style.background="#D2D5DE";

}

function HideTooltip()
{
document.getElementById("Popup").style.display="no ne";
}
</script>

The Div:
</div>
<div id="Popup" class="transparent" >
<table >
<tr>
<td id="L1" align="left"</td>
</tr>
<tr>
<td id="L2" align="left"</td>
</tr>
</table>
</div>
The code that sets what to do onmouseover:

e.Row.Cells(0).Attributes.Add("onmouseover", "ShowTooltip(r,pdate);")
e.Row.Cells(0).Attributes.Add("onmouseout", "HideTooltip();")

So my question is... If the grid is around 700px from the top, and
dispays about 10 rows, and apparently row is what the event is changing
on, how can have the popup showup just left of the row item i've
hovered over. It seems to me both clientY and offsetY are affected by
scrollpositon. and event.OffsetY appear to be relative to the row I'm
hovering over so it don't seem like it will be much help Perhaps If I
could get the Y of the cursor from the very top of the page that might
be good enough.

Nov 20 '06 #1
1 11932

jobs wrote:
I'm trying to understand this and don't get it...

I found some code that looks like it's going to work if I can make
sense of how to position the div.
[...]
Everything works great, except I can't seem to position the div where I
want given scrolling.
[...]
So my question is... If the grid is around 700px from the top, and
dispays about 10 rows, and apparently row is what the event is changing
on, how can have the popup showup just left of the row item i've
hovered over. It seems to me both clientY and offsetY are affected by
scrollpositon. and event.OffsetY appear to be relative to the row I'm
hovering over so it don't seem like it will be much help Perhaps If I
could get the Y of the cursor from the very top of the page that might
be good enough.
If you want to find the position of an element, try Quirksmode:

<URL: http://www.quirksmode.org/js/findpos.html >

To get the position of the cursor when an event occurs:

<URL: http://www.quirksmode.org/js/events_properties.html >

Matt Kruse has a pretty good Position library that will "Find the
position of an object on the page regardless of the layout, css, or
positioning used":

<URL: http://www.javascripttoolbox.com/lib/objectposition/ >

And a utilities library that will do the cursor position thing (among
others):

<URL: http://www.javascripttoolbox.com/lib/util/ >

Use them as-is, or just the bits you're interested in.
--
Rob

Nov 20 '06 #2

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

Similar topics

13
by: Nige | last post by:
I've just given one of my sites (www.wealdbroadband.co.uk) an overhaul. Anyone know if there is a way of fixing text at a certain relative position down a page? I'd like the "(c) 2003 ..." notice...
1
by: Dave Hammond | last post by:
I have an html element (a link) with an onclick handler which opens a popup window, and would like to position that window at the coordinates where the element appears on the page. I have...
1
by: Luqman | last post by:
Where is Form Relative Position and Absolute Position in VS.Net 2005 ? Best Regards, Luqman
8
by: Edward | last post by:
I used to do this all the time in HTML-table layouting. How do I do this in CSS? -------------------------------------------------- <table width="400px"> <tr> <td bgcolor="beige">one line of...
0
by: Rain | last post by:
In the example below. If I have the position:relative in the first div, then the menu disapears when dropped, if I do not have it, then it apears over the top of all the other divs when dropped. ...
9
by: MarwaAlSagheer | last post by:
How can i get relative position in different resolutions using c# ??
5
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...
1
by: mfaisalwarraich | last post by:
Hi everyboyd, im trying to make a function which will keep the cursor to its position if non integer value is entered into a textbox. im using the following code: Public Class Form1 Private...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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,...
0
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...
0
Oralloy
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,...
0
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...

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.