我用鼠标向上发送一些X和Y协调,但是当我双击div时它只发送请求。
我有这个功能。
that.parentNode.style.left = (evt.clientX - diffX) + 'px';
如果我发送带有请求的that.parenNode.style.left
它实际上是在鼠标上运行,但问题是它不会从XML文件中读回来保存协调。
如果我发送evt.clientX
,它会发送协调并将其读回httprequest但我需要双击才能发送。
这是我的代码。
var draggableWindow = document.getElementsByClassName('sticker-drag'),
windowCount = draggableWindow.length,
x, windZ = 1;
function startDrag(evt) {
var diffX = evt.clientX - this.parentNode.offsetLeft,
diffY = evt.clientY - this.parentNode.offsetTop,
that = this;
this.style.zIndex = windZ++;
function moveAlong(evt) {
that.parentNode.style.left = (evt.clientX - diffX) + 'px';
that.parentNode.style.top = (evt.clientY - diffY) + 'px';
}
document.addEventListener("mouseup",
function(e){
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","/project2/php/corrdination.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("textBoxID="+e.target.parentNode.id+"&clientY="+(evt.clientY - diffY)+"&clientX="+(evt.clientX - diffX) );
//console.log(e.target.parentNode.id)
console.log((evt.clientY - diffY))
});
function stopDrag() {
document.removeEventListener('mousemove', moveAlong);
document.removeEventListener('mouseup', stopDrag);
windowClass();
}
function windowClass() {
var windowClass = document.getElementsByClassName("sticker");
for (var i = 0; i < windowClass.length; i++) {
windowClass[i].style.opacity="1";
}
}
document.addEventListener('mouseup', stopDrag);
document.addEventListener('mousemove', moveAlong);
}
for (x = 0; x < windowCount; x += 1) {
draggableWindow[x].addEventListener('mousedown', startDrag);
}