Javascript setPointerCapture在Chrome和Firefox中的行为不同
我在Flexbox里面有一堆方形div。当我在正方形内按下鼠标按钮时,我希望目标正方形的背景发生变化。我想捕捉鼠标,因此当我将鼠标移到捕捉到的方块外并释放鼠标按钮时,背景应变回其原始颜色 这有点难以描述,下面是代码 要重现问题,请执行以下步骤:Javascript setPointerCapture在Chrome和Firefox中的行为不同,javascript,google-chrome,firefox,Javascript,Google Chrome,Firefox,我在Flexbox里面有一堆方形div。当我在正方形内按下鼠标按钮时,我希望目标正方形的背景发生变化。我想捕捉鼠标,因此当我将鼠标移到捕捉到的方块外并释放鼠标按钮时,背景应变回其原始颜色 这有点难以描述,下面是代码 要重现问题,请执行以下步骤: 在正方形上按鼠标左键 按住鼠标左键的同时,将鼠标拖动到正方形外 松开鼠标左键 在Firefox中,它的工作方式与我预期的一样。在Chrome中,背景不会更改回其原始颜色 我尝试捕获窗口和文档的事件 编辑: 在Chrome中似乎没有执行指针捕获和释放 pe
pen.js:6 Uncaught DOMException: Failed to execute 'setPointerCapture' on 'Element': No active pointer with the given id is found.
pen.js:12 Uncaught DOMException: Failed to execute 'releasePointerCapture' on 'Element': No active pointer with the given id is found.
是接口的属性
MouseEvents(如mousedown)不是从PointerEvent继承的,也没有pointerId
属性
您要听的是pointerdown
和pointerup
事件:
onmousedown=e=>console.log('mousedown',e.pointerId)//未定义
onpointerdown=e=>console.log('pointerdown',e.pointerId)//id
pen.js:6 Uncaught DOMException: Failed to execute 'setPointerCapture' on 'Element': No active pointer with the given id is found.
pen.js:12 Uncaught DOMException: Failed to execute 'releasePointerCapture' on 'Element': No active pointer with the given id is found.