Not detecting body.scrollTop and body.scrollLeft in IE6

L

London Boy

Hi, i've done a script that makes a DIV appear and follow the mouse cursor and it works
fine but, it has a small glitch, when i scroll the document, the DIV doesn't appear
beside the cursor but much higher on the page.

In the function that shows the DIV for the first time, the document.body.scroll...
doesn't work, they always return 0, though it works on a website i visited... any
clues? (IE)

In the A tags of links -> onMouseOver="showToolTip('text to display');"

function showToolTip(tipText) {
var MouseX=event.clientX+document.body.scrollLeft+10;
var MouseY=event.clientY+document.body.scrollTop+10;
document.all.ToolTipText.innerHTML= tipText;
document.all.ToolTipText.style.top=MouseY;
document.all.ToolTipText.style.left=MouseX;
document.all.ToolTipText.style.visibility="visible";
}

Any help would be appreciated.
 
L

London Boy

London Boy wrote something like Sat 10 Jan 2004 10:42:59p ...
Hi, i've done a script that makes a DIV appear and follow the mouse
cursor and it works fine but, it has a small glitch, when i scroll the
document, the DIV doesn't appear beside the cursor but much higher on
the page.

In the function that shows the DIV for the first time, the
document.body.scroll... doesn't work, they always return 0, though it
works on a website i visited... any clues? (IE)

In the A tags of links -> onMouseOver="showToolTip('text to display');"

function showToolTip(tipText) {
var MouseX=event.clientX+document.body.scrollLeft+10;
var MouseY=event.clientY+document.body.scrollTop+10;
document.all.ToolTipText.innerHTML= tipText;
document.all.ToolTipText.style.top=MouseY;
document.all.ToolTipText.style.left=MouseX;
document.all.ToolTipText.style.visibility="visible";
}

Any help would be appreciated.

Nevermind, i found the problem... the <!DOCTYPE ... tag on top of the
page... for tos ineterested though here's what it looked like before:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

and now, how it works

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Reference from: http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp
 
K

Keith Bowes

London said:
London Boy wrote something like Sat 10 Jan 2004 10:42:59p ...




Nevermind, i found the problem... the <!DOCTYPE ... tag on top of the
page... for tos ineterested though here's what it looked like before:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

and now, how it works

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Reference from: http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp

Yes, document.body.scrollTop only works in compatibility (aka quirks)
mode. To do it in standard mode, use:
document.documentElement.scrollTop

You can use document.compatMode to check.
 

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
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top