@@ -24,6 +24,8 @@ export default function (e, target, node, place, effect, offset) {
2424 const windowWidth = window . innerWidth
2525 const windowHeight = window . innerHeight
2626
27+ const { parentTop, parentLeft} = getParent ( target )
28+
2729 // Get the edge offset of the tooltip
2830 const getTipOffsetLeft = ( place ) => {
2931 const offset_X = defaultOffset [ place ] . l
@@ -153,8 +155,8 @@ export default function (e, target, node, place, effect, offset) {
153155 return {
154156 isNewState : false ,
155157 position : {
156- left : getTipOffsetLeft ( place ) ,
157- top : getTipOffsetTop ( place )
158+ left : getTipOffsetLeft ( place ) - parentLeft ,
159+ top : getTipOffsetTop ( place ) - parentTop
158160 }
159161 }
160162}
@@ -186,8 +188,9 @@ const getDefaultPosition = (effect, targetWidth, targetHeight, tipWidth, tipHeig
186188 let right
187189 let bottom
188190 let left
189- const disToMouse = 8
191+ const disToMouse = 3
190192 const triangleHeight = 2
193+ const cursorHeight = 12 // Optimize for float bottom only, cause the cursor will hide the tooltip
191194
192195 if ( effect === 'float' ) {
193196 top = {
@@ -199,8 +202,8 @@ const getDefaultPosition = (effect, targetWidth, targetHeight, tipWidth, tipHeig
199202 bottom = {
200203 l : - ( tipWidth / 2 ) ,
201204 r : tipWidth / 2 ,
202- t : disToMouse ,
203- b : tipHeight + disToMouse + triangleHeight
205+ t : disToMouse + cursorHeight ,
206+ b : tipHeight + disToMouse + triangleHeight + cursorHeight
204207 }
205208 left = {
206209 l : - ( tipWidth + disToMouse + triangleHeight ) ,
@@ -266,3 +269,17 @@ const calculateOffset = (offset) => {
266269
267270 return { extraOffset_X, extraOffset_Y}
268271}
272+
273+ // Get the offset of the parent elements
274+ const getParent = ( currentTarget ) => {
275+ let currentParent = currentTarget . parentElement
276+ while ( currentParent ) {
277+ if ( currentParent . style . transform . length > 0 ) break
278+ currentParent = currentParent . parentElement
279+ }
280+
281+ const parentTop = currentParent && currentParent . getBoundingClientRect ( ) . top || 0
282+ const parentLeft = currentParent && currentParent . getBoundingClientRect ( ) . left || 0
283+
284+ return { parentTop, parentLeft}
285+ }
0 commit comments