0

我用鼠标向上发送一些 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);
    } 
4

0 回答 0