网上找了个解决方案,各位感觉可行吗
var touchValue = { x: 5, y: 5, sx: 0, sy: 0, ex: 0, ey: 0 }; //initialize the touch values window.addEventListener("touchstart", function () { var event = event || window.event; touchValue.sx = event.targetTouches[0].pageX; touchValue.sy = event.targetTouches[0].pageY; touchValue.ex = touchValue.sx; touchValue.ey = touchValue.sy; }); window.addEventListener("touchmove", function (event) { var event = event || window.event; event.preventDefault(); touchValue.ex = event.targetTouches[0].pageX; touchValue.ey = event.targetTouches[0].pageY; }); window.addEventListener("touchend", function (event) { var event = event || window.event; var changeX = touchValue.ex - touchValue.sx; var changeY = touchValue.ey - touchValue.sy; //console.log("X:"+changeX+" Y:"+changeY); window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty(); }); function getIsTouch() { var changeX = touchValue.ex - touchValue.sx; var changeY = touchValue.ey - touchValue.sy; if (Math.abs(changeX) <= touchValue.x && Math.abs(changeY) <= touchValue.y) { return true } else return false } $('拖动的元素').on('touchend', function () { if(getIsTouch()){ console.log(1) } });
我的定位为什么一直在左上角啊
求下载币