|
15 | 15 | * - `position` {OBject} {left: {Number}, top: {Number}}
|
16 | 16 | */
|
17 | 17 | export default function (e, target, node, place, desiredPlace, 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
|
@@ -186,13 +194,23 @@ export default function (e, target, node, place, desiredPlace, effect, offset) {
|
186 | 194 | }
|
187 | 195 | }
|
188 | 196 |
|
| 197 | +const getDimensions = (node) => { |
| 198 | + const { height, width } = node.getBoundingClientRect() |
| 199 | + return { |
| 200 | + height: parseInt(height, 10), |
| 201 | + width: parseInt(width, 10) |
| 202 | + } |
| 203 | +} |
| 204 | + |
189 | 205 | // Get current mouse offset
|
190 | 206 | const getCurrentOffset = (e, currentTarget, effect) => {
|
191 | 207 | const boundingClientRect = currentTarget.getBoundingClientRect()
|
192 | 208 | const targetTop = boundingClientRect.top
|
193 | 209 | const targetLeft = boundingClientRect.left
|
194 |
| - const targetWidth = currentTarget.clientWidth |
195 |
| - const targetHeight = currentTarget.clientHeight |
| 210 | + const { |
| 211 | + width: targetWidth, |
| 212 | + height: targetHeight |
| 213 | + } = getDimensions(currentTarget) |
196 | 214 |
|
197 | 215 | if (effect === 'float') {
|
198 | 216 | return {
|
|
0 commit comments