(isMouseInTraget method) to determine whether the mouse is inside a DOM element

//鼠标在元素内部
isMouseInTraget(targetDom, mousePoint) {
    if (!mousePoint) return false;
    let tr = targetDom.getBoundingClientRect();
    let t = { x1: tr.x, x2: tr.x + tr.width, y1: tr.y, y2: tr.y + tr.height };//目标对象的四角顶点坐标
    let isIn =
        mousePoint.clientX >= t.x1 && mousePoint.clientX <= t.x2 &&
        mousePoint.clientY >= t.y1 && mousePoint.clientY <= t.y2;
    return isIn;
},

Guess you like

Origin blog.csdn.net/qq_37860634/article/details/131676525