From ec0d021e9296efc0929381e1201a6608cfb24eb7 Mon Sep 17 00:00:00 2001 From: wanglin25 Date: Mon, 9 May 2022 11:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8A=82=E7=82=B9=E6=A0=87?= =?UTF-8?q?=E6=B3=A8=E5=9C=A8=E8=8A=82=E7=82=B9=E6=BF=80=E6=B4=BB=E5=90=8E?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E9=9A=90=E8=97=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/Node.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/simple-mind-map/src/Node.js b/simple-mind-map/src/Node.js index 900d2651..0e3700f5 100644 --- a/simple-mind-map/src/Node.js +++ b/simple-mind-map/src/Node.js @@ -70,6 +70,7 @@ class Node { this._hyperlinkData = null this._tagData = null this._noteData = null + this.noteEl = null this._expandBtn = null this._lines = [] // 尺寸信息 @@ -444,25 +445,27 @@ class Node { this.style.iconNode(iconNode) node.add(iconNode) // 备注tooltip - let el = document.createElement('div') - el.style.cssText = ` - position: absolute; - padding: 10px; - border-radius: 5px; - box-shadow: 0 2px 5px rgb(0 0 0 / 10%); - display: none; - background-color: #fff; - ` - el.innerText = this.nodeData.data.note - document.body.appendChild(el) + if (!this.noteEl) { + this.noteEl = document.createElement('div') + this.noteEl.style.cssText = ` + position: absolute; + padding: 10px; + border-radius: 5px; + box-shadow: 0 2px 5px rgb(0 0 0 / 10%); + display: none; + background-color: #fff; + ` + } + this.noteEl.innerText = this.nodeData.data.note + document.body.appendChild(this.noteEl) node.on('mouseover', () => { let { left, top } = node.node.getBoundingClientRect() - el.style.left = left + 'px' - el.style.top = top + iconSize + 'px' - el.style.display = 'block' + this.noteEl.style.left = left + 'px' + this.noteEl.style.top = top + iconSize + 'px' + this.noteEl.style.display = 'block' }) node.on('mouseout', () => { - el.style.display = 'none' + this.noteEl.style.display = 'none' }) return { node,