javascript - Getting image coordinates of mouse movement -


i have situation clicking (mouse down) @ position (say x1, y1) on image , moving mouse , releasing mouse (mouse up) @ other location (x2, y2) within image.

i need capture these starting , ending coordinates.

i tried mouseup , mousedown event it's not working. when mousedown @ destination not return anything.

var startx, starty; var endx, endy; if (!document.all)     document.captureevents(event.mouseup); document.onmouseup = endpos;  if (!document.all)     document.captureevents(event.mousedown); document.onmousedown = startpos;  function startpos (event) {    startx = event.offsetx?(event.offsetx):event.pagex - img1.offsetleft;    starty = event.offsety?(event.offsety):event.pagey - img1.offsettop; }  function endpos (event) {    endx = event.offsetx?(event.offsetx):event.pagex - img1.offsetleft;    endy = event.offsety?(event.offsety):event.pagey - img1.offsettop; } 

you can use jcrop this

<script type="text/javascript">  jquery(function($){    $('#target').jcrop({     onchange:   showcoords,     onselect:   showcoords   });  });  // simple event handler, called onchange , onselect // event handlers, per jcrop invocation above function showcoords(c) {   alert('x='+ c.x +' y='+ c.y +' x2='+ c.x2 +' y2='+ x.y2)   alert('w='+c.w +' h='+ c.h) };  </script> 

see here


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -