3

I've recently been trying to implement tooltips to display errors in long documents that contains a scroll bar. I had originally started with using bootstrap tooltips but ran into some limitations with z-index described here: Unable to get Bootstrap Tooltip to display above div when inside scroll pane

I've since tried switching over to tippy.js hoping to have better luck. I have not however been able to get the tooltips to show up programatically using the exact same example as the documentation:

const tip = tippy('#myButton')
const el = document.querySelector('#myButton')
const popper = tip.getPopperElement(el)
tip.show(popper)

Basically it still has the normal hover behavior. I've created a jsfiddle example of almost exactly how my current page is laidout and hoping to trigger the tooltip to show on page load, not on hover!

Here is the jsfiddle: https://jsfiddle.net/L3jv4a9w/1/

1
  • is the below what you are looking for? Commented Aug 18, 2017 at 21:18

1 Answer 1

1

The issue is with the element selector you were using.

If you update your code to the following it works

const tip = tippy('.root2');
const el = document.querySelector('.root2')
const popper = tip.getPopperElement(el);
tip.show(popper);

See js fiddle here or example in action below.

const tip = tippy('.root2');
const el = document.querySelector('.root2')
const popper = tip.getPopperElement(el)
tip.show(popper)
<link href="https://unpkg.com/[email protected]/dist/tippy.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/tippy.js"></script>


<div class="root2" title="This is a tooltip"> <b>Tooltip</b>
</div>

2
  • Oops that was an oversight on my part. I had copied my code over from my app. You only used 5 random elements before/after the tooltip. Notice how when you do 20+ random text elements and the tooltip is not shown in the current scroll pane it dispalys at the bottom of the screen. This was a limitation I saw with the bootstrap tooltip and I believe it had to do with absolute vs relative positioning
    – Josh L
    Commented Aug 18, 2017 at 23:56
  • I will give you the points for this because this solved my original issue. But perhaps ask my follow up question on their github as this may be a limitation of the library
    – Josh L
    Commented Aug 18, 2017 at 23:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.