javascript - 如何使用 Tippy.js 在 mouseenter 上显示工具提示并在单击时隐藏

标签 javascript tooltip tippyjs

我正在使用 Tippy.js .我想在 mouseenter 上显示工具提示,但在单击时隐藏它。

当您单击带有 .tippy 的元素时,这会触发工具提示并保持打开状态,直到您单击离开。

tippy('.tippy', { trigger: 'click' });

这会在您使用 .tippy 在元素上鼠标输入 时显示工具提示,并在鼠标离开 .tippy 元素时隐藏。

tippy('.tippy', { trigger: 'mouseenter' });

我想要两者的结合。在 mouseenter 上显示工具提示,但在我点击离开之前保持打开状态。

我更喜欢**不监听点击事件和鼠标输入事件,而是在使用 { trigger: 'manual' } 时手动显示和隐藏它

此外,请您解释一下{custom}触发选项。来自文档:

{custom} refers to the fact that you can have any event listener, but it won't have the opposite "hide" event.

我可以使用 {custom} 触发器来查找我要查找的内容吗?怎么办?

非常感谢!

最佳答案

根据版本,您可以使用生命周期 Hook 更新触发器:

  • v5: setProps() 方法
  • v3-v4:set() 方法

两者的工作原理相同。

tippy('.tippy', {
  trigger: 'mouseenter',
  onShow(instance) {
    // v5
    instance.setProps({trigger: 'click'});
    // v3-v4
    // instance.set({trigger: 'click'});
  },
  onHide(instance) {
    // v5
    instance.setProps({trigger: 'mouseenter'});
    // v3-v4
    // instance.set({trigger: 'mouseenter'});
  }
});

关于javascript - 如何使用 Tippy.js 在 mouseenter 上显示工具提示并在单击时隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45246206/

相关文章:

javascript - 在 underscore.js 模板中转义 <%- %> 标签

javascript - 将键盘和鼠标移动映射到后台网页

javascript - 将输入字段值传递到 angularjs $resource undefined 并且错误显示未知范围提供程序

c# - IsBalloon 属性使 Windows 窗体工具提示位置不一致

internet-explorer - 当 span 是 anchor 的子项时,不显示标题工具提示

javascript - 如何使用默认按钮来关闭tippyjs的工具提示

javascript - 在其中绘制垂直虚线和圆圈的折线图

tooltip - nv.d3同时触发页面多图的工具提示

input - 在 Tippy 工具提示中包含输入字段

javascript - 无法为工具提示制作 css 三 Angular 形