jQuery UI工具提示手动打开/关闭 [英] jquery ui tooltip manual open /close

查看:142
本文介绍了jQuery UI工具提示手动打开/关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以手动打开关闭jquery ui工具提示?我只希望它对切换开/关的点击事件做出反应.您可以取消绑定所有鼠标事件,并且在调用.tooltip('open')时会重新绑定它们,即使这不应该初始化或设置imo事件,因为如果您尝试运行.tooltip('open')而不进行初始化,它会抱怨大声说没有初始化.

is there a way to manually open close the jquery ui tooltip? I just want it to react to a click event toggling on/off. You can unbind all mouse events and it will rebind them when calling .tooltip('open'), even though that should not initialize or set events imo, since if you try to run .tooltip('open') without initializing, it complains loudly about not being initialized.

推荐答案

jltwoo,我可以建议使用两个不同的布尔开关来启用自动打开和自动关闭吗?进行此更改后,您的代码将如下所示:

jltwoo, can I suggest to use two different boolean switches to enable auto-open and auto-close? With this change your code will look like this:

(function( $ ) {
  $.widget( "custom.tooltipX", $.ui.tooltip, {
    options: {
        autoShow: true,
        autoHide: true
    },

    _create: function() {
      this._super();
      if(!this.options.autoShow){
        this._off(this.element, "mouseover focusin");
      }
    },

    _open: function( event, target, content ) {
      this._superApply(arguments);

      if(!this.options.autoHide){
        this._off(target, "mouseleave focusout");
      }
    }
  });

}( jQuery ) );

通过这种方式,将工具提示初始化为:

In this way, initializing the tooltip as:

$(someDOM).tooltipX({ autoHide:false });

当鼠标悬停在元素上时,它会自动显示,但您必须手动将其关闭.

it shows by itself when the mouse is over the element but you have to manually close it.

如果要手动控制打开和关闭操作,则可以简单地使用:

If you want to manually control both open and close actions, you can simply use:

$(someDOM).tooltipX({ autoShow:false, autoHide:false });

这篇关于jQuery UI工具提示手动打开/关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆