【问题标题】:Get under mouse - current DOM element obj [while event-resize ] jQuery-ui获取鼠标 - 当前 DOM 元素 obj [while event-resize] jQuery-ui
【发布时间】:2016-06-16 13:33:02
【问题描述】:

我已经设置了一个函数来跟踪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 
});

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

收集 resize 事件数据的正确方法是什么?

【问题讨论】:

  • 我会使用 resize 事件:resize: function(e, ui){ var x = e.clientX; var y = e.clientY; }`
  • @Twisty 谢谢你的建议,我试试看..

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


【解决方案1】:

在 Javascript 中你可以这样做:

document.elementFromPoint(x, y);

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

您可以从那里获取所需元素的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-12
    • 2022-12-05
    • 2010-09-09
    • 1970-01-01
    • 2011-05-14
    • 2017-06-23
    • 1970-01-01
    • 2011-02-12
    相关资源
    最近更新 更多