Giter Club home page Giter Club logo

Comments (1)

ly525 avatar ly525 commented on May 13, 2024

bindContextMenu (e) {
e.preventDefault() // 不显示默认的右击菜单
if (
e.target.classList.contains('element-on-edit-canvas') ||
e.target.parentElement.classList.contains('element-on-edit-canvas')
) {
const { x, y } = this.$el.getBoundingClientRect()
this.contextmenuPos = [e.clientX - x, e.clientY - y]
} else {
this.hideContextMenu()
}
},

给在编辑模式下画布上的元素添加 class: 'element-on-edit-canvas 的原因

在右击画布上的时候(编辑模式),会显示右键菜单,如果右击的是画布上的某个元素(这一部分的判断就是通过 e.target.classList.contains('element-on-edit-canvas') 来实现的

  1. 只有编辑模式,才会给元素上添加 element-on-edit-canvas class
  2. 此外就是 如果是在 非画布画布上元素之间的空白区域右击,也是不会出现右键菜单的
可能这个 className 变成 element-with-context-menu 会更好理解

from luban-h5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.