PointerCaptureing OnLoad

时间:2019-06-17 07:57:25

标签: javascript

我尝试使用指针捕获并在浏览器窗口之外跟踪鼠标位置,但是它仅在mousedown时有效,我尝试模拟mousedown事件,但仅在将元素悬停时才有效(任何人都可以帮助我找到正确的方法捕获指针并跟踪它是否包含在浏览器窗口plz之外。

var evt = new MouseEvent("pointerdown", {
    view: window,
    bubbles: true,
    cancelable: false
    /* whatever properties you want to give it */
}),
    capture = document.getElementById('renderCanvas');

function beginCapture(e) {
capture.onpointermove = capturing;
capture.setPointerCapture(e.pointerId);
}

function capturing(e) {
console.log(e.clientX, e.clientY);
}

capture.onpointerdown = beginCapture;
capture.dispatchEvent(evt);

1 个答案:

答案 0 :(得分:0)

通常,无法在浏览器窗口之外跟踪鼠标/指针的位置。但是,当用户开始拖动操作时,某些浏览器可能会继续触发mousemove事件。