How to make bootstrap tooltip remain visible till the link is clicked

前端 未结 2 1626
轮回少年
轮回少年 2020-12-24 12:18

I have a link which I am going to use as notification when a user has some new notification I am going to notify the user by showing a tooltip(twitter bootstrap tooltip). Wh

相关标签:
2条回答
  • 2020-12-24 12:47

    You can add a variable to trigger off the mouseleave event to re-show the tooltip, and then as you said in your comment, just destroy the tooltip when clicked, so it doesn't show when you mouseover again:

    var clickedNotify = false;
    $('p a').tooltip({placement: 'bottom'}).tooltip('show');
    $('p a').mouseleave(function() { if (!clickedNotify) { $('p a').tooltip({placement: 'bottom'}).tooltip('show'); } });
    $('p a').click(function() { clickedNotify = true; $(this).tooltip('destroy'); });
    

    This way, the tooltip is always shown, even after a mouseleave, until the link is clicked. After the link is clicked, the tooltip is destroyed, and still won't generate javascript errors on the page on mouseleave.

    0 讨论(0)
  • 2020-12-24 12:52

    Here is the solution http://jsfiddle.net/testtracker/QsYPv/8/

    Added the option "trigger"

    $('p a').tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show');
    

    then, with this line

    $('p a').on('click',function(){$(this).tooltip('destroy');});
    

    destroy tooltip on click.

    0 讨论(0)
提交回复
热议问题