开发者

How do I correctly show a JQuery Tool tooltip only on mouse click?

Whenever a user clicks a menu item I want to show a tooltip:

// Initialize tooltips for each menu_item
$(".menu_item_tooltip_link a.tooltip").tooltip({
    opacity: 1.0,
    position: "bottom center",
    effect: "slide",
    direction: "bottom",
    offset: [0, 0],
    relative: true,
    events: { def: "click,mouseout", tooltip: "mouseenter" }
})开发者_开发知识库;

The tooltip should never be hidden, unless the user clicks the tooltip's close button:

$(".menu_item_tooltip_close").click(function () {
    $(this).parents(".menu_item_tooltip:first").hide();
});

Everything is working fine, but when the tooltip is closed and the cursor stays in the element that triggered the tooltip it will not be shown until I leave the bounds of the item and click it again.

Any idea how to fix this?


I found the solution myself. The problem was using the JQuery hide() function instead of the api hide() function. Here is how it works:

$(".menu_item_tooltip_close").click(function () {
    var element = $(this).parents(".menu_item_tooltip_link:first").find(
       "a.tooltip");
    var tip = element.data("tooltip");
    tip.hide();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜