获取鼠标 - 当前DOM元素obj [while event-resize] jQuery-ui

时间:2016-03-03 09:48:21

标签: jquery jquery-ui jquery-ui-resizable

我设置了一个函数来跟踪document上的鼠标事件,即使我只需要 鼠标专门用于重新尺寸检测目的至少此时......

var BoolMouseDown = false;
var BoolResizing = false;
document.body.onmousedown = function () {
    BoolMouseDown = true;
};
document.body.onmouseup = function () {
    BoolMouseDown = false;
};

上的

sideNote:目标是获取鼠标下每个元素的数据,以便它可以转换为在征服者中幸存的新(div)部分

// called function on resiz event

var ValueCurSourceCellId = "";
var ValueCurDestCellId = "";
function CurCellIdSet(val) {
     if (BoolMouseDown) {
        ValueCurDestCellId = val;
        BoolMouseDown = false;
    }
    else {
        if (BoolResizing) {
            ValueCurDestCellId = val;
        }
        ValueCurSourceCellId = val;
    }
}


var BoolHasCollided  = false;
$(gitem11)
.mouseover(function () {
   //cur mouse over = attribute of html-imput-hidden( curMoRszr="")
   if (BoolMouseDown) return;//so if its Mouse Down - don't collect underlying element data

   $elmHidData1.attr('curMoRszr', $(this).attr('id'));
   CurCellIdSet($(this).attr('id'));
})
.mousedown(function () {
   BoolMouseDown = true;
   $elmHidData1.attr('curMoRszr', $(this).attr('id'));
   CurCellIdSet($(this).attr('id'));
})
.mouseup(function () {
   BoolMouseDown = false;
   CurCellIdSet($(this).attr('id'));
})
.resizable({

   handles: "e, s", ghost: true,
   start: 
       // here 11 is the accident producer, 21 is the victim.
       function () {
           console.log("resize started");
           curg21initialpositionTop = $curg21.offset().top;
           curg11initialpositionTop = $curg11.offset().top;
           curg11initialHeight = $curg11.css("height").substring(0, 2);
   },

   resize: 

        function (event, ui) {

             var data1id = $elmHidData1.attr('curMoRszr');
             if (ui.size.height + curg11initialpositionTop > curg21initialpositionTop && ui.size.height + curg11initialpositionTop < curg21initialpositionTop + 50 + gap)
             {
                setRszble($curg11, $curg21);
                BoolHasCollided  = true;
             }

             $(gitem31).text("p: " + ui.size.height + "curg21initialuiposition:" + curg21initialuiposition + ", " + ui.position.top);
       },
       stop:
      // function to conclude the accident, give the new partial div a position and size 
});

在这里问SO时,我发现的最近的帖子是This^

在调整大小事件上收集数据的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

在Javascript中你可以这样做:

document.elementFromPoint(x, y);

其中x和y将是鼠标位置(我假设你可以自己获得指针位置)

从那里你可以从你需要的元素中获取数据。