javascript - In PaperJS how to link onMouseUp event to origin of onMouseDown event when mouse has moved away from item -


in paperjs project have bunch of objects have circle path associated them. these paths each have mouse functions.

what i'd create links between 2 circles when clicking on one, dragging mouse, , releasing mouse button on circle.

for use paperjs onmousedown , onmouseup events, implemented inside object:

function circleobj() { // object constructor    this.circle = new path(...);    this.circle.onmousedown = function(event) {       //eventstuff    } } 

where this.circle circle path.

the problem when release mouse button no longer linked circle, , onmouseup function doesn't execute until click on actual circle again. therefore doesn't allow drag , drop on other circle, since 'drop' action doesn't register.

how can have onmouseup event register , linked circle onmousedown event took place?

if want keep mouse events tied constructor, think easiest keep initial point in global variable. it's cleaner adding , removing tool event view , checking see if hit object circle , not line or other object.

var firstpoint = null;  function circleobj(p) {     this.circle = new path.circle({        center: p,        radius: 20,        fillcolor: 'red'     });     this.circle.onmousedown = function(event) {             firstpoint = this.position;     }     this.circle.onmouseup = function(event) {         if (firstpoint !== null){             var path = new path.line({                 from: firstpoint,                 to: this.position,                 strokecolor: 'black',                 strokewidth: 40,                 strokecap: 'butt'             });             path.sendtoback();             firstpoint = null;         }     } }  function onmousedown(event){     if (!event.item){         circleobj(event.point);         firstpoint = null;     } } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -