|
15 | 15 | * - `position` {OBject} {left: {Number}, top: {Number}} |
16 | 16 | */ |
17 | 17 | export default function (e, target, node, place, effect, offset) { |
18 | | - const tipWidth = node.clientWidth |
19 | | - const tipHeight = node.clientHeight |
| 18 | + const { |
| 19 | + width: tipWidth, |
| 20 | + height: tipHeight |
| 21 | + } = getDimensions(node) |
| 22 | + |
| 23 | + const { |
| 24 | + width: targetWidth, |
| 25 | + height: targetHeight |
| 26 | + } = getDimensions(target) |
| 27 | + |
20 | 28 | const {mouseX, mouseY} = getCurrentOffset(e, target, effect) |
21 | | - const defaultOffset = getDefaultPosition(effect, target.clientWidth, target.clientHeight, tipWidth, tipHeight) |
| 29 | + const defaultOffset = getDefaultPosition(effect, targetWidth, targetHeight, tipWidth, tipHeight) |
22 | 30 | const {extraOffset_X, extraOffset_Y} = calculateOffset(offset) |
23 | 31 |
|
24 | 32 | const windowWidth = window.innerWidth |
@@ -161,13 +169,23 @@ export default function (e, target, node, place, effect, offset) { |
161 | 169 | } |
162 | 170 | } |
163 | 171 |
|
| 172 | +const getDimensions = (node) => { |
| 173 | + const { height, width } = node.getBoundingClientRect() |
| 174 | + return { |
| 175 | + height: parseInt(height, 10), |
| 176 | + width: parseInt(width, 10) |
| 177 | + } |
| 178 | +} |
| 179 | + |
164 | 180 | // Get current mouse offset |
165 | 181 | const getCurrentOffset = (e, currentTarget, effect) => { |
166 | 182 | const boundingClientRect = currentTarget.getBoundingClientRect() |
167 | 183 | const targetTop = boundingClientRect.top |
168 | 184 | const targetLeft = boundingClientRect.left |
169 | | - const targetWidth = currentTarget.clientWidth |
170 | | - const targetHeight = currentTarget.clientHeight |
| 185 | + const { |
| 186 | + width: targetWidth, |
| 187 | + height: targetHeight |
| 188 | + } = getDimensions(currentTarget) |
171 | 189 |
|
172 | 190 | if (effect === 'float') { |
173 | 191 | return { |
|
0 commit comments