var holdFlag = false, id_scale = document.getElementById("scale"), moveFlag = false, holdTimestamp = 0, touches = [], size = 0.01, _scale = 1, touch1X, touch2X; var touchArea = document.querySelector('#touchArea'); touchArea.addEventListener('touchstart', function (event) { event.preventDefault(); holdFlag = true; holdTimestamp = (new Date()).getTime(); touches = event.touches; //alert(1) //console.log(1) //alert(touches.length) //touch1X = touches[0].clientX; //if (touches.length == 2) { //touch1X = touches[0].clientX; // touch2X = touches[1].clientX; // } }, false); touchArea.addEventListener('touchmove', function (event) { event.preventDefault(); var _touches = event.touches; moveFlag = true; if (touches.length == 2) { if (holdFlag) { touch1X = touches[0].clientX; touch2X = touches[1].clientX; holdFlag = false; } if ((touch1X > _touches[0].clientX && touch2X < _touches[1].clientX) || (touch1X == _touches[0].clientX && touch2X < _touches[1].clientX) || (touch1X > _touches[0].clientX && touch2X == _touches[1].clientX)) {//放大 _scale = _scale + size; //alert(2 + " " + _scale) console.log(2) if (_scale < 2 && _scale > 1) id_scale.style.transform = 'scale(' + _scale + ')'; } else if ((touch1X < _touches[0].clientX && touch2X > _touches[1].clientX) || (touch1X == _touches[0].clientX && touch2X > _touches[1].clientX) || (touch1X < _touches[0].clientX && touch2X == _touches[1].clientX)) {//缩小 _scale = _scale - size; // alert(3 + " " + _scale) console.log(3) if (_scale > 1 && _scale < 2) id_scale.style.transform = 'scale(' + _scale + ')'; } } });不知道最后两个判断不知道问题出在哪里了 最上面的明明是代表手势撑开 然后有时候会放大有时候会缩小
添加回答
举报
0/150
提交
取消