Tooltip With image issue.
See original GitHub issueI am using TippyJS in my project but i am facing an issue with tooltip + Image
Output I am getting
Output Should Be

JS Code
let $arg = this.arg( $fid + 'tooltip' );
$arg[ 'performance' ] = false;
if ( $arg[ 'image' ] !== false ) {
$arg.html = '#wponiontooltipimagetippy';
$arg.updateDuration = 2000;
$arg.followCursor = false;
$arg.livePlacement = true;
$arg.inertia = true;
$arg.onShow = function () {
const content = this.querySelector( '.tippy-content' );
if ( $tip.loading ) return;
$tip.loading = true;
fetch( $arg[ 'image' ] ).then( resp => resp.blob() ).then( blob => {
const url = URL.createObjectURL( blob );
content.innerHTML = `<img src="${url}">`;
$tip.loading = false;
} ).catch( e => {
content.innerHTML = 'Loading failed';
$tip.loading = false;
} );
};
$arg.onHidden = function () {
const content = this.querySelector( ".tippy-content" );
content.innerHTML = '';
};
$arg[ 'popperOptions' ] = {
modifiers: {
preventOverflow: {
enabled: false
},
hide: {
enabled: false
}
}
};
}
$tip = tippy( this.elem[ 0 ], $arg );
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Tooltip on image - html - Stack Overflow
The problem is the <img> tag is self closing, so you can't add another element inside of it. – Justin. May 13, 2020...
Read more >Vega-tooltip image support · Issue #7635 - GitHub
I have to check but I think the name of the field needs to be 'image'. All reactions.
Read more >Creating Tooltips for Images with CSS - The Orniphile
Tooltips can be created with the HTML title attribute, but the resulting tooltip stays visible for only a few seconds and it can't...
Read more >Tooltip image too big - Visual Studio Feedback
Tooltip image for dockerfile fills almost the whole screen, which makes it unusable. I use a second screen and the resolution is 4K....
Read more >No tooltip over images with link on Confluence 4.1 - Jira
I have an icon as png and linked to a page, during mouse hover I get the name of the file instead of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found


Sure, here you go https://codepen.io/anon/pen/YvdEjg?editors=0010
I made a custom function
onImageDimensionsKnownthat invokes the callback once thenaturalWidthproperty is some truthy value (i.e. 1px or more) by testing it every 5ms. I’m not sure what a “safe” value is here such that there are no 1 frame glitches where the popper is incorrectly positioned though.The key code is here:
This seems to work. When the tooltip is flipped on show it does transition undesirably, but it’s not incorrectly placed.
Notes:
onShowget passed the relevant tippy instance as an argumentonShow(instance),popperInstanceis a property of tippy instances.createPopperInstanceOnInit: trueensures the popper instance is available for the first show because it is lazily created for increased performance by default.Okay, I think the issue is that the
MutationObserverdetects the innerHTML content change, but the image doesn’t begin loading yet and doesn’t affect the layout of the tooltip, so its position is updated too soon.You might need to detect when the image’s dimensions become known by the browser, and then call
tip.popperInstance.update()to manually update the tooltip’s position.Or set a
widthorheightattribute on the image so that the dimensions are known.