question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tooltip With image issue.

See original GitHub issue

I am using TippyJS in my project but i am facing an issue with tooltip + Image

Output I am getting

http://s.svarun.in/xn image


Output Should Be

image


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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
atomikscommented, Jun 29, 2018

Sure, here you go https://codepen.io/anon/pen/YvdEjg?editors=0010

I made a custom function onImageDimensionsKnown that invokes the callback once the naturalWidth property 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:

content.innerHTML = `<img src="${url}">`
onImageDimensionsKnown(content.querySelector('img'), instance.popperInstance.update)

This seems to work. When the tooltip is flipped on show it does transition undesirably, but it’s not incorrectly placed.

Notes:

  • onShow get passed the relevant tippy instance as an argument onShow(instance),
  • popperInstance is a property of tippy instances.
  • createPopperInstanceOnInit: true ensures the popper instance is available for the first show because it is lazily created for increased performance by default.
1reaction
atomikscommented, Jun 29, 2018

Okay, I think the issue is that the MutationObserver detects 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 width or height attribute on the image so that the dimensions are known.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found