Popover delay at bootstrap doesnt work

天大地大妈咪最大 提交于 2019-12-01 16:28:10

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.

I have tried your code, the problem in your code is that the tooltip does not seem be bound within the body, it is actually going outside the body, so if you will leave the margin for the element you would be able to get it working correctly. Take a look at this :

JSFiddle

HTML :

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

JS :

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

});

My solution: Popover opens only when the user hover over the link for a certain amount of time.

$('.popMonster').popover({
    html: true,
    trigger: 'manual',
    delay: { 
        show: 100, 
        hide: 0
    },
    container: $(this).attr('id'),
    placement: 'auto',
    content: function () {
        $return = '<div class="hover-hovercard"></div>';
    }
}).on("mouseenter", function () {

    var delay_ = (function(){
        var timer_ = 0;
        return function(callback, ms){
            clearTimeout (timer_);
            timer_ = setTimeout(callback, ms);
        };
    })();

    var self = $(this), url = '/myurl/action';

    delay(function(){
        // Get content via ajax:
        $.get(url, function(data) {
            if(data == 'Unauthorized.'){
                location.href = './';
            }else{
                self.attr('data-content', data);
                self.popover("show");
            }
        });
    }, 800 ); // time to wait before call ajax

    self.siblings(".popover").on("mouseleave", function () {
        self.popover('hide');
    });

})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!