拖动可以了,但是touchend执行不到,执行到就会触发click事件。
可以来个人帮帮忙不。。。。。
View点击事件监听:
nativeView.addEventListener("click", function(e) {
var clientX = e.clientX;
var clientY = e.clientY;
var target = e.target;
if (0 < e.clientY && e.clientY <= 40) {
mui.alert('点击按钮1');
} else {
mui.toast('点击按钮2');
}
});
View拖动监听:
nativeView.addEventListener("touchstart", function(event) {
flag = true;
var touch;
if (event.touches) {
touch = event.touches[0];
} else {
touch = event;
}
cur.x = touch.clientX;
cur.y = touch.clientY;
});
nativeView.addEventListener("touchmove", function(event) {
if (flag) {
var touch;
if (event.touches) {
touch = event.touches[0];
} else {
touch = event;
}
moveX = touch.pageX - cur.x;
moveY = touch.pageY - cur.y;
x = moveX;
y = moveY;
if (x < 0) {
x = 0;
} else if (x > (boxWidth - modelWidth)) {
x = sreenWidth - 40;
}
if (y < 0) {
y = 0;
} else if (y > (boxHeight - modelHeight)) {
y = (boxHeight - modelHeight);
}
nativeView.setStyle({
top: y + 'px',
left: x + 'px'
});
// 原本是touchend里的内容,判断离那边近停靠哪边
setTimeout(function(){
var pointX = x + modelWidth / 2;
var pointY = y + modelHeight / 2;
if (pointX < boxWidth / 2) {
x = 0;
} else {
x = sreenWidth - 40;
}
nativeView.setStyle({
top: y + 'px',
left: x + 'px'
});
},1000);
}
});