SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need Mouse Position in IE when i click on l link

    Hi all,

    I am facing a problem in getting mouse position when I click on a link, specialy the Y coordinate of the mouse position.
    I am using this code

    [COLOR=Sienna]if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
    } else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
    } else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
    }
    // Global variables
    xMousePos = 0; // Horizontal position of the mouse on the screen
    yMousePos = 0; // Vertical position of the mouse on the screen
    xMousePosMax = 0; // Width of the page
    yMousePosMax = 0; // Height of the page

    function captureMousePosition(e) {
    if (document.layers) {
    xMousePos = e.pageX;
    yMousePos = e.pageY;
    xMousePosMax = window.innerWidth+window.pageXOffset;
    yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
    xMousePos = window.event.x+document.body.scrollLeft;
    yMousePos = window.event.y+document.body.scrollTop;
    xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
    yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
    xMousePos = e.pageX;
    yMousePos = e.pageY;
    xMousePosMax = window.innerWidth+window.pageXOffset;
    yMousePosMax = window.innerHeight+window.pageYOffset;
    }

    window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;

    }[/
    COLOR]

    It works fine for mouse move and displayes correct mouse pos in status bar.

    But when on mouse click i try to get the position it return the xMousePos good, but yMousePos it return is related to the browser client area in IE rather than the my document ( html ).

    So when i try to place a div their it is placed near top of the document bcoz it ignores the scrolling information. or the

    document.body.scrollLeft

    document.body.scrollTop
    is always 0( zero ) as i debug it.

    Please help me or give any new idea or fix the code.

    for demo u can see the link

    http://team-kh.awpdc.com/~muarijaz/walter_1295_260/members3.php

    Try to click on the top small icon of two icons with each small image. You will notice that for above two blocks the Panel will popup at the right place but for last two blocks near bottom of the page the panel will popup on top of the page.

    Thanks.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Getting the location of a link is easier than getting the location of the mouse. Is the location of the link not acceptable for this?

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for Reply .

    Whatever i wana show a div right blow that link so if i get the position of the link it may work too, remeber the link is a image in an anchor tag

    Regards

    Mudassar Ijaz


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •