18910140161

JavaScript-instance.show在PageLoad上尝试5秒后显示tippy.JS时不是函数错误-堆栈溢出

顺晟科技

2022-10-18 13:07:27

138

我使用TippyJS在悬停时显示一个文本弹出窗口,但我也想在5秒后在PageLoad上显示这个弹出窗口,所以我这样做:

const instance = tippy('.tooltippy', {
    trigger: 'mouseenter',
    allowHTML: true,
    placement: 'left',
    animation: 'scale-subtle',
    interactive: true,
    content: function (reference) {
        return reference.querySelector('.tooltipcontent');
    }
});

setTimeout(function() {
  instance.show();
}, 5000);

但5秒钟后,我得到:

Uncaught TypeError: instance.show is not a function

而我的Tippyjs工作正常。

我的HTML:

<span class="whatsappicon tooltippy" title="Chat met ons!">
  <span class="whaplabel tooltipcontent">Stel je vraag!</span>
  <a href="url" target="_blank">
    <img src="images/custom/whatsapp_online.png" alt="Open Whatsapp">
  </a>
</span>

该怎么做才能在5秒钟后打开这个小尖头?


顺晟科技:

更新了我的问题,因为我没有看到您将其直接分配给HtmlCollection.Tippy需要绑定到NodeList或元素类型,因此我们需要首先获取元素并将其分配给它。

这个例子应该是可行的:

const tooltippy = document.getElementById('tooltippy')

const instance = tippy(tooltippy, {
    trigger: 'mouseenter',
    allowHTML: true,
    placement: 'left',
    animation: 'scale-subtle',
    interactive: true,
    content: function (reference) {
        return reference.querySelector('.tooltipcontent');
    }
});

setTimeout(function() {
  instance.show();
}, 5000);
<代码><;script SRC=“ https://unpkg.com/@popperjs/core@2/dist/UMD/Popper.min.JS ”>;<;/script>;<;script SRC=“ https://unpkg.com/tippy.js@6/dist/tip-bundle.UMD.JS ”>;<;/script>;<;span CLASS=“ WhatsAppIcon ” ID=“ Tooltippy ” TITLE=“聊天工具!”>;<;span Class=“ whapLabel TooltipContent ”>;stel je vraag!<;/span>;<;a href=“ URL ” target=“_空白”>;<;IMG SRC=“ images/custom/WhatsApp_在线.PNG ” alt=“打开WhatsApp ”>;<;/a>;<;/span>;

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航