将元素尺寸(浮动)与鼠标坐标(整数)进行比较

I have a <div> on webpage with the following dimensions:

enter image description here

使用Javascript / jQuery,我获得了该元素的以下位置和尺寸:

$elem.offset()
{top: 1434.4791564941406, left: 32.222225189208984}
$elem.outerWidth()
930
$elem.outerHeight()
536.788

It seems to me that a MouseEvent contains clientX and clientY coordinates in "number" type.

Question: Why is it that a onmouseenter event fires with a clientX value of 31 or 32 (depending on how quickly I move the mouse), both of which should be outside of the element’s border box.

Question: Converting floats to integers probably isn’t a good idea because of rounding. So, how do I go about checking the border box here: convert the mouse coordinates to floats? Meaning, that a (1434, 32) mouse coordinate is just outside whereas (1435, 33) is barely inside of the bounding box?

评论