Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取鼠标在drop jquery上的位置_Jquery_Jquery Ui_User Interface_Draggable - Fatal编程技术网

获取鼠标在drop jquery上的位置

获取鼠标在drop jquery上的位置,jquery,jquery-ui,user-interface,draggable,Jquery,Jquery Ui,User Interface,Draggable,使用jQueryUI进行一些拖放操作。我必须知道物品是否掉到了div之外,所以我需要知道鼠标在stop上的位置,但它没有按照我希望的方式工作 以下是我到目前为止的情况: function getMouseXY() { var tempX, tempY; document.onmouseup = getMouseXY; function getMouseXY(e) { tempX = e.pageX tempY = e.pageY

使用jQueryUI进行一些拖放操作。我必须知道物品是否掉到了div之外,所以我需要知道鼠标在stop上的位置,但它没有按照我希望的方式工作

以下是我到目前为止的情况:

function getMouseXY() {
    var tempX, tempY;
    document.onmouseup = getMouseXY;
    function getMouseXY(e) {
        tempX = e.pageX
        tempY = e.pageY
        console.log("last xy: " + [tempX, tempY]);
        return [tempY, tempX];
    } 
}

var currentMousePosition = [];

$(".mcCirc").each(function(index){
    $(this).draggable({
        revert: "invalid",
        stop: function( event, ui) {
            currentMousePosition = getMouseXY();

        }
    });
});

当您删除事件时,您正在附加该事件,而该事件本应在删除操作发生之前完成

如果您包含更多示例代码,则会更好:-)

但我还是举了个例子:


啊,德普。我以为在我放下它的时候它会触发,但我猜这个方法也会在mouseup上被调用?这是有道理的。
document.onmouseup = getMouseXY; // Attached too late.

var posX = 0;
var posY = 0;

// This is better
$(document).mousemove(function(e){
    $('#status').html(e.pageX +', '+ e.pageY);
    posX = e.pageX;
    posY = e.pageY;
});