【问题标题】:Make tipsy tooltip sticky on click and normal on click again使醉酒的工具提示在点击时保持粘性并在再次点击时正常
【发布时间】:2023-03-12 02:05:01
【问题描述】:

当您点击它的 hot* 元素时,如何让您的工具提示像粘性一样永久保留,并在您再次点击它时返回正常行为?
* = 触发工具提示的元素

【问题讨论】:

  • -1。自我回答时,您应该解释所有内容,包括预回答代码。至于答案,代码转储绝不是一个好的答案。像不适合你一样提问和回答。
  • Jee,你真的很讨厌,包括已经因此而否决了它。它在问题中。但我会改变它。
  • 顺便说一句,解释在代码的 cmets 中。我见过这样的流行答案。不过还好,现在好多了。

标签: jquery tipsy


【解决方案1】:

这意味着您必须取消绑定 mouseleave 事件并在交替单击时重新绑定它。 通过变量交替点击,例如醉意棒。 mouseleave 的问题是我们不知道原始事件。在主要的醉酒代码中搜索了一下后,调用醉酒离开函数的方法如下:$(this).tipsy().leave if $(this) 是热点区域。

工作代码:

    $('.tooltip')
        .click(function() {
            /*Sticky and back on click*/
            //Remember status (and already reverse here, so also defined)
            this.tipsyStick=!this.tipsyStick;
            //Bind or rebind depending on status
            if (this.tipsyStick) 
                $(this).unbind('mouseleave'); 
            else
                $(this).bind('mouseleave', $(this).tipsy().leave);
        })
        //General tipsy triggering
        .tipsy();

请注意,虽然醉酒可能通过live() 而不是bind() 绑定它,具体取决于您的初始选项。在这种情况下,请分别使用 dielive 相应地更改 mouseleave 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多