Tippyjs: Reset a tippy instance

Created on 26 Jul 2019  路  4Comments  路  Source: atomiks/tippyjs

I have the code below. I want the tooltip to show up on the mouse, and then go away when the mouse moves. This works with the code below.

However, I want the tooltip to show again if the mouse stops moving, but this does not happen. It happens if I move off the element and move back on to it though.

Is there a way to reset the tooltip so that the mouse does not need to be moved off?

window.addEventListener('DOMContentLoaded', function(e) {
            tippy("#tooltip", {
                animation: 'scale',
                duration: 200,
                placement: "bottom",
                arrow: false,
                followCursor: "initial",
                delay: [500, 200],
                onShown: function (e) {
                    document.getElementById('po-table').addEventListener('mousemove', function (e2) {
                        e.hide(200);
                    });
                },
            });
        });
馃挕 question

All 4 comments

You can add a timout inside onShown, something like that:

if (x) clearTimeout(x);
x = setTimeout(e.show , 200); 

and you will also need to stop it when mouse is outside the element
so to wrap it all up you'll need something like this:

    onShown: function(e) {
      myElement.addEventListener("mousemove", function() {
        e.hide(200);
        if (x) clearTimeout(x);
        x = setTimeout(e.show , 200); 
      });
      myElement.addEventListener("mouseleave", function() {
      if (x) clearTimeout(x);
      });
    }

here is a small codepen to see it in action : https://codepen.io/wyzix33/pen/rXWyoP

Hope it helps

Thank you, that does work but does not reset the pop-up position.

Ah, i got confused by placement: "bottom"
Test this out:
https://codepen.io/wyzix33/pen/gVLdLa
Hope it helps :)

Perfect. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

faroukcharkas picture faroukcharkas  路  4Comments

Christian24 picture Christian24  路  3Comments

skazhikadyadya picture skazhikadyadya  路  3Comments

mreinstein picture mreinstein  路  5Comments

dariadomagala picture dariadomagala  路  5Comments