mirari / v-viewer

Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
https://mirari.cc/v-viewer/
MIT License
2.5k stars 295 forks source link

监听mousedown事件,只有鼠标滚轮和右键能触发,鼠标左键不能触发 #335

Closed yzw625 closed 3 months ago

yzw625 commented 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';

// 将 Canvas 添加到 canvas 层上 image.parentElement.appendChild(canvas);`

但是给canvas元素添加mousedown监听事件,只有鼠标滚轮和右键能触发,左边不能触发,请问会是什么原因呢?

mirari commented 3 months ago

image的父元素.viewer-canvas上有一个pointerdown监听事件,会阻止点击左键的默认行为。 这个是viewerjs上的逻辑,似乎没法靠配置的方式规避 canvas只要位于viewer-canvas外面就不会有这个问题