jquery - How to click at position in Canvas using Javascript? -
i want click canvas element have id mycanvas
width: 500, height: 200.
in javascript, have method this?
using page ruler
- chrome extension position include parameter x
, y
.
i tried code:
function relmousecoords(event){ var totaloffsetx = 220; var totaloffsety = 100; var canvasx = 500; var canvasy = 200; var currentelement = this; do{ totaloffsetx += currentelement.offsetleft - currentelement.scrollleft; totaloffsety += currentelement.offsettop - currentelement.scrolltop; } while(currentelement = currentelement.offsetparent) canvasx = event.pagex - totaloffsetx; canvasy = event.pagey - totaloffsety; console.log(canvasx, convasty); return {x:canvasx, y:canvasy} } htmlcanvaselement.prototype.relmousecoords = relmousecoords;
click on element via js can done trigger.
using jquery:
x_coord = 1; y_coord = 1; var e = jquery.event( "mousedown", { pagex: x_coord, pagey: y_coord } ); $('#mycanvas').trigger(e); // execute more code x_coord = 255; y_coord = 255; var e = jquery.event( "mouseup", { pagex: x_coord, pagey: y_coord } ); $('#mycanvas').trigger(e);
Comments
Post a Comment