Detecting if a tag wordwraps?

M

mmurrell

I am developing some dhtml code that displays a balloon style help when
a user mouses over words. The balloon help is positioned correctly
until the tag (in this case) word-wraps. Is there any way in JS to
detect and get the correct coordinates? I have tried disabling
word-wrap on the span tag in css, but the offsetTop + offsetHeight
still points to the top of the word (the same place vertically it would
have been positioned before the word wrap.

Thank you for any help.
 
R

RobG

I am developing some dhtml code that displays a balloon style help when
a user mouses over words. The balloon help is positioned correctly
until the tag (in this case) word-wraps. Is there any way in JS to
detect and get the correct coordinates? I have tried disabling
word-wrap on the span tag in css, but the offsetTop + offsetHeight
still points to the top of the word (the same place vertically it would
have been positioned before the word wrap.

To get the co-ordinates of the top left corner of an element, use the
stuff from Quirksmode:

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


To find the height and width of the element itself:

<URL:http://www.quirksmode.org/viewport/elementdimensions.html>


You probably need only consider offsetWidth and offsetHeight. Using
the above two references, you should be able to find the position and
size of the element, then position your balloon accordingly.

You might find it useful to put the balloon text in the element's title
attribute so the HTML guys can set it to whatever and your JS just
displays it. It might then also appear as a 'tool tip' where JS is
disabled -or maybe that's a completely useless suggestion. :)
 

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

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top