2016-08-31 3 views

答えて

3

これを解決するのに役立つかもしれないJointJSでいくつかのドキュメント化されていない方法があります。より多くのインライン。

paper.on('blank:pointerdown', function(evt, x, y) { 

    var linkView = this.getDefaultLink() 
      .set({ 
       'source': { x: x, y: y }, 
       'target': { x: x, y: y } 
      }) 
      .addTo(this.model) 
      .findView(this); 

    // initiate the linkView arrowhead movement 
    linkView.startArrowheadMove('target'); 

    $(document).on({ 
     'mousemove.example': onDrag, 
     'mouseup.example': onDragEnd 
    }, { 
     // shared data between listeners 
     view: linkView, 
     paper: this 
    }); 


    function onDrag(evt) { 
     // transform client to paper coordinates 
     var p = evt.data.paper.snapToGrid({ 
      x: evt.clientX, 
      y: evt.clientY 
     }); 
     // manually execute the linkView mousemove handler 
     evt.data.view.pointermove(evt, p.x, p.y); 
    } 

    function onDragEnd(evt) { 
     // manually execute the linkView mouseup handler 
     evt.data.view.pointerup(evt); 
     $(document).off('.example'); 
    } 

}); 
+0

ありがとうございました!!!それは魅力のように働いています。私はJavascriptとJointJSの新人です。 mousemoveとmouseupのそれぞれの関数が呼び出されたことを理解できました。しかし、どのように使用されていますか?マウスイベントに.exampleを割り当てることの重要性は何ですか? – ACHU

+0

デモが正しく動作することは重要ではありません。私は[namespaces](https://api.jquery.com/event.namespace/)を 'onDragEnd()'の 'mousemove'と' mouseup'リスナーの両方を参照するためにのみ使用しました。 – Roman

+0

うん!わかった。私はそれがマウスイベントを参照するために使用される名前空間だと思います。 – ACHU

関連する問題