0

Hey guys im creating script. And i need a liltle help. Ive got this mouse position script but when i use the function, it shows about 1000px even if my cursor is in about 200px top. What can i do to fix this and get normal mouse position. Please help.

     $s .= ('<td id="start_'.$currentTasken.'" nowrap="nowrap" align="center" ondblclick="editCellValue(this)" style="' . $style . '" title="'.$AppUI->_('Double click to edit date').'">' 
<script>
            var cursorX;
            var cursorY;
            document.onmousemove = function(e){
                cursorX = e.pageX;
                cursorY = e.pageY;
            }
            function editCellValue(cellElement) {
                document.getElementById('cellValueEditorDiv').style.display = 'block';
                document.getElementById('cellValueEditorDiv').style.top = cursorX;
                document.getElementById('cellValueEditorDiv').style.left = cursorY;
            }
</script>
McLaren
  • 776
  • 1
  • 10
  • 23

1 Answers1

1

I have create a simple jsFiddle for you McLaren, when you click inside of the div it will show the mouse position X and Y relative to the div. you can use offsetX and offsetY to work this out

https://jsfiddle.net/6g2ybvp5/1/

Javascript

function mouseCords(e) {
    alert(e.offsetX + " " + e.offsetY);
}

document.getElementById("cellValueEditorDiv").addEventListener("click", mouseCords, false);
Canvas
  • 5,779
  • 9
  • 55
  • 98