function drag(obj){
obj.
addEventListener(
"touchstart",
function(event){
var e=event;
console.
log(
e)
var abc=e.targetTouches[
0].pageX;
var xyz=e.targetTouches[
0].pageY;
console.
log(
abc+":"+xyz)
//var aaa=obj.offsetTop+obj.offsetHeight;
obj.
addEventListener(
"touchmove",
function(event){
var e=event;
var l=e.targetTouches[
0].clientX
-abc;
//一直变化的X;
var t=e.targetTouches[
0].clientY
-xyz;
//一直变化的Y;
//console.log(t)
if(
l<0){
l=0;
else ifl>=document-//console.log(l)
l=document-
ift<0t=0else ift >= document- t = document-
if(
t >= window.innerHeight
/10){
t=window.innerHeight
/10
};
console.
log(
l)
obj.
style.
cssText='left:'+(
l)
+'px;top:'+(
t)
+'px;cursor:move;';
})
obj.
addEventListener(
"touchend",
function(event){
obj.
style.
cssText='left:0px;top:0px;cursor:move;';
})
return false;
})
}
直接在html里面drag(这里面就是需要拖拽的dom元素)
css用的是定位
转载请注明原文地址: https://www.6miu.com/read-2622169.html