Return to Snippet

Revision: 48642
at July 7, 2011 00:29 by devnull69


Updated Code
if(window.addEventListener) {
   element.addEventListener('mousemove', handleMouseClick, false);
} else {
   element.attachEvent('onmousemove', handleMouseClick);
}

function handleMouseClick(e) {
   if(window.event) e = window.event;

   // mouse position relative to the top of the document
   var xpos = e.pageX - this.offsetLeft;
   var ypos = e.pageY - this.offsetTop;

   // mouse position relative to the viewport
   //var xpos = e.clientX - this.offsetLeft;
   //var ypos = e.clientY - this.offsetTop;
}

Revision: 48641
at July 7, 2011 00:29 by devnull69


Updated Code
if(window.addEventListener) {
   element.addEventListener('mousemove', handleMouseClick, false);
} else {
   element.attachEvent('onmousemove', handleMouseClick);
}

function handleMouseClick(e) {
   if(window.event) e = window.event;

   // mouse position relative to the top of the document
   var xpos = e.pageX - this.offsetLeft;
   var ypos = e.pageY - this.offsetTop;

   // mouse position relative to the viewport
   //var xpos = event.clientX - this.offsetLeft;
   //var ypos = event.clientY - this.offsetTop;
}

Revision: 48640
at July 7, 2011 00:01 by devnull69


Updated Code
element.addEventListener('mousemove', handleMouseClick, false);

function handleMouseClick(e) {
   var xpos = e.pageX - this.offsetLeft;
   var ypos = e.pageY - this.offsetTop;
}


// IE
element.attachEvent('onmousemove', handleMouseClickIE);

function handleMouseClickIE() {
   var xpos = event.clientX - this.offsetLeft;
   var ypos = event.clientY - this.offsetTop;
}

Revision: 48639
at July 6, 2011 23:58 by devnull69


Initial Code
element.addEventListener('mousemove', handleMouseClick, false);

function handleMouseClick(e) {
   var xpos = e.pageX - this.offsetLeft;
   var ypos = e.pageY - this.offsetTop;
}


// IE
element.attachEvent('onmousemove', handleMouseClickIE);

function handleMouseClickIE() {
   var xpos = event.pageX - this.offsetLeft;
   var ypos = event.pageY - this.offsetTop;
}

Initial URL

                                

Initial Description

                                

Initial Title
Mouse position inside an element

Initial Tags

                                

Initial Language
JavaScript