【问题标题】:Tooltipster close all before opening a new one, click/hover combinationTooltipster 在打开一个新的之前关闭所有,单击/悬停组合
【发布时间】:2017-02-01 15:55:26
【问题描述】:

我正在使用tooltipster 来构建一些标注。我有一些点击,一些悬停。

JS:

var instances = $.tooltipster.instances();

$('.mgu-click').tooltipster({
  functionBefore: function(instance, helper) {
    $.each(instances, function(i, instance) {
      instance.close();
    });
  },
  contentCloning: true,
  trigger: 'click',
  'maxWidth': 280,
  'minHeight': 280,
  animation: 'grow',
  interactive: true,
  arrow: false,
  distance: -10,
  contentAsHTML: true,
  theme: 'tooltipster-shadow'
});
$('.mgu-hover').tooltipster({
  functionBefore: function(instance, helper) {
    $.each(instances, function(i, instance) {
      instance.close();
    });
  },
  contentCloning: true,
  trigger: (browser.hasTouchEvents()) ? 'click' : 'hover',
  'maxWidth': 280,
  'minHeight': 280,
  animation: 'grow',
  interactive: true,
  arrow: false,
  distance: -10,
  contentAsHTML: true,
  theme: 'tooltipster-shadow'
});

如果您单击或移动到工具提示器-btn,则所有其他都应在所选打开之前关闭。 functionBefore 与触发器一起正常工作:单击。但是如果我用触发器悬停调用那个,所有其他的都不会关闭。

感谢帮助

【问题讨论】:

    标签: javascript jquery tooltipster


    【解决方案1】:

    您似乎需要在functionBefore 函数中调用$.tooltipster.instances() 方法以引用最新实例:

    functionBefore: function(instance, helper){
      $.each($.tooltipster.instances(), function(i, instance){
        instance.close();
      });
    }
    

    【讨论】:

    • 非常感谢!我已经自定义了打开/关闭操作:单击(元素)以打开工具提示,然后单击工具提示 html 中的按钮将其关闭,因此上述代码可以完美地确保一次只打开一个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多