Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript setPointerCapture在Chrome和Firefox中的行为不同_Javascript_Google Chrome_Firefox - Fatal编程技术网

Javascript setPointerCapture在Chrome和Firefox中的行为不同

Javascript setPointerCapture在Chrome和Firefox中的行为不同,javascript,google-chrome,firefox,Javascript,Google Chrome,Firefox,我在Flexbox里面有一堆方形div。当我在正方形内按下鼠标按钮时,我希望目标正方形的背景发生变化。我想捕捉鼠标,因此当我将鼠标移到捕捉到的方块外并释放鼠标按钮时,背景应变回其原始颜色 这有点难以描述,下面是代码 要重现问题,请执行以下步骤: 在正方形上按鼠标左键 按住鼠标左键的同时,将鼠标拖动到正方形外 松开鼠标左键 在Firefox中,它的工作方式与我预期的一样。在Chrome中,背景不会更改回其原始颜色 我尝试捕获窗口和文档的事件 编辑: 在Chrome中似乎没有执行指针捕获和释放 pe

我在Flexbox里面有一堆方形div。当我在正方形内按下鼠标按钮时,我希望目标正方形的背景发生变化。我想捕捉鼠标,因此当我将鼠标移到捕捉到的方块外并释放鼠标按钮时,背景应变回其原始颜色

这有点难以描述,下面是代码

要重现问题,请执行以下步骤:

  • 在正方形上按鼠标左键
  • 按住鼠标左键的同时,将鼠标拖动到正方形外
  • 松开鼠标左键
  • 在Firefox中,它的工作方式与我预期的一样。在Chrome中,背景不会更改回其原始颜色

    我尝试捕获窗口和文档的事件

    编辑: 在Chrome中似乎没有执行指针捕获和释放

    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.