Not detecting body.scrollTop and body.scrollLeft in IE6

Discussion in 'Javascript' started by London Boy, Jan 11, 2004.

  1. London Boy

    London Boy Guest

    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.
    --
    ¤ £õñþõñ ßõ¥ ¤
     
    London Boy, Jan 11, 2004
    #1
    1. Advertising

  2. London Boy

    London Boy Guest

    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

    --
    ¤ £õñþõñ ßõ¥ ¤
     
    London Boy, Jan 11, 2004
    #2
    1. Advertising

  3. London Boy

    Keith Bowes Guest

    London Boy wrote:
    > 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
    >


    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.
     
    Keith Bowes, Jan 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    5,887
  2. Replies:
    0
    Views:
    683
  3. Replies:
    0
    Views:
    1,148
  4. =?Utf-8?B?SGFyZHkgV2FuZw==?=

    HTML document.body.scrollTop question

    =?Utf-8?B?SGFyZHkgV2FuZw==?=, Feb 22, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,684
    bruce barker
    Feb 23, 2007
  5. MadMad
    Replies:
    2
    Views:
    155
    MadMad
    Jul 3, 2007
Loading...

Share This Page