2
我已經成功地實現縮放特徵基於this examplePaperJS縮放和平移
zoom: function(delta, point){
if (!delta) return;
var
oldZoom = paper.view.zoom,
oldCenter = paper.view.center,
viewPos = paper.view.viewToProject(point);
newZoom = delta > 0 ? oldZoom * 1.05 : oldZoom/1.05;
if (!this.allowedZoom(newZoom)) return;
var
zoomScale = oldZoom/newZoom,
centerAdjust = viewPos.subtract(oldCenter),
offset = viewPos.subtract(centerAdjust.multiply(zoomScale)).subtract(oldCenter);
paper.view.center = view.center.add(offset);
},
allowedZoom: function(zoom){
zoom = Math.max(zoom, this.settings.minZoom);
zoom = Math.min(zoom, this.settings.maxZoom);
if (zoom !== paper.view.zoom)
{
paper.view.zoom = zoom;
return zoom;
}
return null;
}
但是這並沒有考慮到,當你縮小回原來的scale = 1
視圖的位置。我的意思是我希望觀點能夠堅持畫布邊緣。