need click twice after hide a shown bootstrap popover

后端 未结 7 1549
情书的邮戳
情书的邮戳 2020-11-30 03:14



        
相关标签:
7条回答
  • 2020-11-30 03:24

    I recently came across this bug and this is how I fixed it:

    $('.myPopoverClass')
        .popover({
            trigger: 'manual', /* <- important, instantiates popover */
            container: 'body', /* optional */
            animation: false
        })
        .click(function(e) {
            $('.popover').not(this).hide(); /* optional, hide other popovers */
            $(this).popover('show'); /* show popover now it's setup */
            e.preventDefault();
        });
    
    0 讨论(0)
  • 2020-11-30 03:35

    Simply use this:

    $('[data-toggle="popover"]').popover('toggle');
    

    Instead of:

    $('[data-toggle="popover"]').popover();
    
    0 讨论(0)
  • 2020-11-30 03:38

    make sure popover will be initialized only once.if it will be initialized more than one time across different files you may get this problem.

    $('[data-toggle=popover]').popover({
        placement : 'bottom'
    });
    
    0 讨论(0)
  • 2020-11-30 03:41

    It's a bug in v3.3.5:

    https://github.com/twbs/bootstrap/issues/16732

    Just use 3.3.4 for now until it is fixed.

    0 讨论(0)
  • 2020-11-30 03:43

    Still not fixed in 3.3.6 but I found a proposed solution here:

    https://github.com/twbs/bootstrap/issues/16732

    https://github.com/twbs/bootstrap/pull/17702/files#diff-f3e99e0bb007ace7a370f0492b9cb5abR340

    I've applied it in the hidden event:

    $('body').on('hidden.bs.popover', function (e) {
        $(e.target).data("bs.popover").inState.click = false;
    });
    

    This works for me. To be exactly the same as the proposed fix it would be:

    $('body').on('hidden.bs.popover', function (e) {
        $(e.target).data("bs.popover").inState = { click: false, hover: false, focus: false }
    });
    

    Note: I use delegated popovers which is why i'm using the $('body') reference.

    For Bootstrap 4 use _activeTrigger instead of inState:

    $(e.target).data("bs.popover")._activeTrigger.click = false
    
    0 讨论(0)
  • 2020-11-30 03:44

    I had a popup that fades out after 3 secs and needed double click to reopen it. Followed Darren's solution and it worked.

    $(function () {
    
        $('#popLinks').popover({
            html: true,
            trigger: 'manual',
            animation: true
        });
    
        $('#popLinks').click(function () {
            $(this).popover('show');
            setTimeout(function () {
                $('.popover').fadeOut('slow');
            }, 3000);
            e.preventDefault();
        });    
    });
    
    0 讨论(0)
提交回复
热议问题