Javascript mouse coordinate help

  • gogetit

    #5020

    Hi,

    Kind of uncommon question, but maybe you can help me out.

    I have a js which get the X,Y coordinate of the mouse, and display an image when going on some links, right next to the mouse position.

    I changed my theme to Graphene (which is a great theme!), but now my script gets the coordinate way off the mouse location.

    Here’s the code. id is a string variable of the div to display, and e is the event when the function is called.

    Any help Would be appreciated. Right now my image is displayed way to the right and near the bottom of the screen.

    THANKS!

    EDIT: here’s a screenshot to explain the situation.

    dYyvX.png

    var myId=document.getElementById(id);
    //capture the mouse
    //e = e || window.event;
    myId.style.position = "absolute";

    //screenX,screenY
    var posx = 0;
    var posy = 0;
    //if (!e) var e = window.event;

    var offsetx=true;
    var offsety=true;
    if (/MSIE (d+.d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
    var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    if (ieversion>=8) offsetx=false;
    else if (ieversion>=7) offsetx=false;
    else if (ieversion>=6) offsetx=false;
    else if (ieversion>=5) offsetx=false;
    }

    if(e){
    if (e.pageX || e.pageY) {
    posx = e.pageX;
    posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
    posx = e.clientX;
    posy = e.clientY;
    if(offsetx){
    posx = posx + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    }
    if(offsety){
    posy = posy + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    }
    //posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    //posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    //alert(posx + ' x '+posy);
    if (posx>450) posx=450;
    myId.style.top = (posy + 5) +"px";
    myId.style.left = (posx + 10) +"px";
    //myId.style.top = e.clientY + 10 +"px";
    //myId.style.left = e.clientX + 10 +"px";

    StockMenuShow(id);
    }
    Admin

    Syahir Hakim

    #30339

    Moved to Support. Please post in the correct section next time.

    Please also include the link to your site so that we can take a look.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Do NOT follow this link or you will be banned from the site!