How to pan using paperjs

余生颓废 提交于 2021-01-27 05:45:40

问题


I have been trying to figure out how to pan/zoom using onMouseDrag, and onMouseDown in paperjs.
The only reference I have seen has been in coffescript, and does not use the paperjs tools.


回答1:


you can simplify Sam P's method some more:

var toolPan = new paper.Tool();
toolPan.onMouseDrag = function (event) {
    var offset = event.downPoint - event.point;
    paper.view.center = paper.view.center + offset;
};

the event object already has a variable with the start point called downPoint.

i have put together a quick sketch to test this.




回答2:


This took me longer than it should have to figure out.

var toolZoomIn = new paper.Tool();
toolZoomIn.onMouseDrag = function (event) {
    var a = event.downPoint.subtract(event.point);
    a = a.add(paper.view.center);
    paper.view.center = a;
}


来源:https://stackoverflow.com/questions/32540165/how-to-pan-using-paperjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!