I am creating an application where i need to zoomin/zoomout a document on finger pinch. I used Viewport.js for the same but there is a small limitation with that. When the document is redrawn its redrawn only from top-left. I need the effect to be shown in atleast 2 directions. Also i need the code in javascript.
else if (evt.touches != null && evt.touches.length == 2) {
//when touched with 2 fingers, i.e for zooming
//Zooming only if the page is opened in 'view' mode
if (pageScope.mode == 'view') {
var touchx1 = evt.touches[0].pageX;
var touchy1 = evt.touches[0].pageY;
var touchx2 = evt.touches[1].pageX;
var touchy2 = evt.touches[1].pageY;
var distXY = Math.sqrt(Math.pow((touchx2 - touchx1), 2) + Math.pow((touchy2 - touchy1), 2));
if (distXY > dist) {
viewport.zoomIn();
} else if (distXY < dist) {
viewport.zoomOut();
}
viewport.draw();
dist = distXY;
}
}
The attached code detects 2 fingers touch and executes the zoom accordingly. Can anyone suggest how this can be achieved?