Javascript mouse coordinate help

  • gogetit



    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.


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


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

    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.pageX || e.pageY) {
    posx = e.pageX;
    posy = e.pageY;
    else if (e.clientX || e.clientY) {
    posx = e.clientX;
    posy = e.clientY;
    posx = posx + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    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; = (posy + 5) +"px"; = (posx + 10) +"px";
    // = e.clientY + 10 +"px";
    // = e.clientX + 10 +"px";


    Syahir Hakim


    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.
Graphene Themes Forum