diff --git a/docs/package-lock.json b/docs/package-lock.json index 7a8ce0f..abe8988 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -17,7 +17,7 @@ }, "..": { "name": "@svelte-plugins/tooltips", - "version": "2.0.1", + "version": "2.1.0", "dev": true, "license": "MIT", "devDependencies": { diff --git a/docs/src/App.svelte b/docs/src/App.svelte index 6960eea..fc16369 100644 --- a/docs/src/App.svelte +++ b/docs/src/App.svelte @@ -16,13 +16,13 @@
This tooltip should appear on the top when clicked. The content for the tooltip is provided by the title
attribute.
This tooltip should appear on the Tooltip Top
This is an example of using HTML and content wrapping.
', position: 'top', animation: 'slide', arrow: false }}>top.This is an example of using HTML and content wrapping.
', position: 'top', animation: 'slide', arrow: false }}>top"} /> @@ -262,6 +262,10 @@ margin-bottom: 40px; } + .example.relative { + position: relative; + } + :global(.tooltip.tooltip-theme) { --tooltip-background-color: hotpink; --tooltip-box-shadow: 0 1px 8px pink; diff --git a/package.json b/package.json index cd3d5fc..70f69aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@svelte-plugins/tooltips", - "version": "2.1.0", + "version": "2.1.1", "license": "MIT", "description": "A simple tooltip action and component designed for Svelte.", "author": "Kieran Boyle (https://github.com/dysfunc)", diff --git a/src/helpers.js b/src/helpers.js index e662de3..a68e24a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -69,6 +69,19 @@ export const computeTooltipPosition = (containerRef, tooltipRef, position, coord } else if (elementPosition === 'absolute' || elementPosition === 'relative') { cumulativeOffsetTop -= parseFloat(computedStyle.top) || 0; cumulativeOffsetLeft -= parseFloat(computedStyle.left) || 0; + + if (elementPosition === 'relative') { + cumulativeOffsetTop -= currentElement.offsetTop; + cumulativeOffsetLeft -= currentElement.offsetLeft; + } + } + + const transform = computedStyle.transform; + + if (transform && transform !== 'none') { + const transformMatrix = new DOMMatrix(transform); + cumulativeOffsetTop -= transformMatrix.m42; + cumulativeOffsetLeft -= transformMatrix.m41; } currentElement = currentElement.parentElement;