//拖动组件 $('#drag1').udraggable(); //约束配置 $(selector).udraggable({opt1: value1, opt2: value2}); //在父元素内移动元素 $('#drag2').udraggable({ containment: 'parent' });
网上找了个解决方案,各位感觉可行吗
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) } });