I am writing a jquery plugin that allows users to pinch and zoom into an image. The user can then pan around the image using one touch.
I have got it all working but the panning around the image is very fast and I need to slow this down. I was hoping someone may have some suggestions. Unfortunately I am not allowed to use some of the libraries out there such as hammer JS.
Here is the code for panning around the image.
var pos = $this.position();
var top = (pos.top + (orig.changedTouches[0].pageY - offsetPos.y)),
left = (pos.left +(orig.changedTouches[0].pageX - offsetPos.x));
//Apply Limits to keep image in viewport
var viewWidth = ($this.parent().width());
var X_LIMIT = viewWidth - $this.width();
var viewHeight = ($this.parent().height());
var Y_LIMIT = viewHeight - $this.height();
if (left > viewWidth) { left = viewWidth; }
if (left < X_LIMIT) { left = X_LIMIT; }
if (top > viewHeight) { top = viewHeight; }
if (top < Y_LIMIT) { top = Y_LIMIT; }
if(top >0){top = 0;}
if(left >0){left = 0;}
$this.css({
top: top,
left: left
});
Any help would be much appreciated.