diff --git a/src/scaffolding/context-menu.js b/src/scaffolding/context-menu.js index 7c57579..56e8e5d 100644 --- a/src/scaffolding/context-menu.js +++ b/src/scaffolding/context-menu.js @@ -7,7 +7,8 @@ class ContextMenu { this.root = document.createElement('div'); this.root.className = styles.contextMenu; - this._onmousedown = this._onmousedown.bind(this) + this._onmousedown = this._onmousedown.bind(this); + this._onresize = this._onresize.bind(this); } _onmousedown (e) { @@ -16,6 +17,10 @@ class ContextMenu { } } + _onresize () { + this.destroy(); + } + add (option) { const item = document.createElement('button'); item.className = styles.contextMenuItem; @@ -32,6 +37,7 @@ class ContextMenu { show (mouseEvent) { document.addEventListener('mousedown', this._onmousedown); + window.addEventListener('resize', this._onresize); const layersRect = this.parent.layersRect; const x = mouseEvent.clientX - layersRect.left + 1; const y = mouseEvent.clientY - layersRect.top + 1; @@ -41,6 +47,7 @@ class ContextMenu { destroy () { document.removeEventListener('mousedown', this._onmousedown); + window.removeEventListener('resize', this._onresize); this.root.remove(); } }