Skip to content

Commit

Permalink
修改获取元素位置bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jy03078959 committed Dec 3, 2019
1 parent 1b035fa commit c4356bd
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/assets/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,15 @@ function modifyNodeId(tree, idCache = [], exclude = [], key = 'id', childKey = '
* @param {DOM}} node
*/
function getNodePosition(node) {
var _node = node
var top = 0
var left = 0
var elPosition = node.style.position || window.getComputedStyle(node).position
if (elPosition === 'fixed') {
var stageRect = getNoRotateBoundingClientRect(document.getElementById('stage'))
top = stageRect.top
left = stageRect.left
}

while (node) {
if (node.tagName) {
top = top + node.offsetTop + node.clientTop
left = left + node.offsetLeft + node.clientLeft
node = node.offsetParent
} else {
node = node.parentNode
}
var pos = node.getBoundingClientRect()
//变换简单处理,计算一个元素在旋转之前相对根节点的top left
var centerPoint = {
x: pos.left + pos.width / 2,
y: pos.top + pos.height / 2
}
return {
top: top - _node.clientTop,
left: left - _node.clientLeft
top: centerPoint.y - node.offsetHeight / 2,
left: centerPoint.x - node.offsetWidth / 2,
}
}
/**
Expand Down

0 comments on commit c4356bd

Please sign in to comment.