|
使用touch 例子的代码 实现了缩放功能,但是拖拽的时候图片会恢复原来的尺寸 求怎么解决
- Model.prototype.pinch = function(event){//双指缩放
- var id = this.getIDByXID('pinch');
- var target = document.getElementById(id);
- target.style.webkitTransition = 'all ease 0.05s';
- //////////////////////////缩放
- touch.on('#' + id, 'touchstart', function(ev){//按下
- ev.preventDefault();
- });
- var initialScale = 1;
- var currentScale;
- touch.on('#' + id, 'pinch', function(ev){//双指缩放
- ev.hasStopedPropagation = true;
- currentScale = ev.scale - 1;
- currentScale = initialScale + currentScale;
- currentScale = currentScale > 2 ? 2 : currentScale;//最大倍数2
- currentScale = currentScale < 1 ? 1 : currentScale;//最小倍数1
- this.style.webkitTransform = 'scale(' + currentScale + ')';
- });
-
- touch.on('#' + id, 'pinchend', function(ev){//缩放弹起
- initialScale = currentScale;
- });
- ///////////////////////////拖拽
- var dx, dy;
- touch.on('#' + id, 'drag', function(ev){//拖拽
- dx = dx || 0;
- dy = dy || 0;
- var offx = dx + ev.x + "px";
- var offy = dy + ev.y + "px";
- this.style.webkitTransform = "translate(" + offx + "," + offy + ")";
- });
-
- touch.on('#' + id, 'dragend', function(ev){//拖拽弹起
- dx += ev.x;
- dy += ev.y;
- });
-
- };
复制代码 |
|