Closed yzw625 closed 3 months ago
使用背景:在modal模式下覆盖一层canvas元素,通过给canvas元素添加鼠标事件,如下代码: const canvas = document.createElement('canvas'); const rect = image.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; canvas.style.position = 'absolute'; canvas.style.top =${rect.top}px; canvas.style.left =${rect.left}px`; canvas.style.zIndex = '9999'; canvas.style.pointerEvents = 'auto'; canvas.style.border = '1px solid red';
const canvas = document.createElement('canvas'); const rect = image.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; canvas.style.position = 'absolute'; canvas.style.top =
; canvas.style.left =
// 将 Canvas 添加到 canvas 层上 image.parentElement.appendChild(canvas);`
但是给canvas元素添加mousedown监听事件,只有鼠标滚轮和右键能触发,左边不能触发,请问会是什么原因呢?
image的父元素.viewer-canvas上有一个pointerdown监听事件,会阻止点击左键的默认行为。 这个是viewerjs上的逻辑,似乎没法靠配置的方式规避 canvas只要位于viewer-canvas外面就不会有这个问题
使用背景:在modal模式下覆盖一层canvas元素,通过给canvas元素添加鼠标事件,如下代码:
const canvas = document.createElement('canvas'); const rect = image.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; canvas.style.position = 'absolute'; canvas.style.top =
${rect.top}px; canvas.style.left =
${rect.left}px`; canvas.style.zIndex = '9999'; canvas.style.pointerEvents = 'auto'; canvas.style.border = '1px solid red';// 将 Canvas 添加到 canvas 层上 image.parentElement.appendChild(canvas);`
但是给canvas元素添加mousedown监听事件,只有鼠标滚轮和右键能触发,左边不能触发,请问会是什么原因呢?