canvas - Javascript addEventListener within addEventListener -
this silly question, i'm having hard time sequence of event listeners shouldn't running time basically. want click button allow mouse events performed on <canvas>
element. on mousedown
there logged console, , long the mouse down want statement logging console, , on mouseup
there should final statement , mousemove
logging cease. @ current, anytime after first mousedown
, there mousemove
logging, ignoring mup
boolean stop it. might there's wrong nesting event listeners, wasn't aware of problems might cause...
here's code far, appreciated:
function mousemove() { var mx = canvas_x, = canvas_y; console.log('move: ' + mx + ',' + + ',' + mouseup); } btnrect.addeventlistener('click', function (event) { drect = false; c.addeventlistener('mousedown', function () { var x = canvas_x, y = canvas_y; mouseup = false; console.log('down: ' + x + ',' + y + ',' + mouseup); if(mouseup === false) { c.addeventlistener('mousemove', mousemove); } else if (mouseup === true) { c.removeeventlistener('mousemove', mousemove); } else { c.removeeventlistener('mousemove', mousemove); } }); c.addeventlistener('mouseup', function () { var ex = canvas_x, ey = canvas_y; mouseup = true; console.log('up: ' + ex + ',' + ey + ',' + mouseup); }); });
Comments
Post a Comment