Search code examples
jquerytwitter-bootstrappopover

Popover delay at bootstrap doesnt work


I want the popover to hide after a while. I coded this -> CODE work..

JS

$('#qoo').popover({
    placement : 'left',
    html : true,
    delay: { 
             show: 500, 
             hide: 100
    },
    content: function() {
    return $('#content-wrapper1').html();
}                 

});

HTML

<div class="span1 offset1">
     <a href="#" id="qoo" rel="popover" data-original-title="TITLEEEE" class="circle"> textttt</a>
     <div id="content-wrapper1" class="content-wrapper"> texttttttat</div> 
</div>

But it doesn't work.


Solution

  • Delay show / hide does not automatically show / hide the popover, it defines the delays before doing so! Also, delay does not apply to manual trigger type, so you must have a trigger, like hover. to get the delays to work.

    $('#qoo').popover({
        placement : 'right',
        html : true,
        trigger : 'hover', //<--- you need a trigger other than manual
        delay: { 
           show: "500", 
           hide: "100"
        },
        content: function() {
            return $('#content-wrapper1').html();
        }
    });
    

    However, to achieve automatically hide for the popover, you can do the following by hooking into the shown.bs.popover event :

    $('#qoo').on('shown.bs.popover', function() {
        setTimeout(function() {
            $('#qoo').popover('hide');
        }, 1000);
    });
    

    The above hides the popover after 1000 ms, 1 second.