Ответ 1
Вы можете обрабатывать события show
и hide
для popover:
$('#example').popover({
html: true,
trigger: 'hover',
container: '#example',
placement: 'bottom',
content: function () {
return '<div class="box">here is some content</div>';
},
animation: false
}).on({
show: function (e) {
var $this = $(this);
// Currently hovering popover
$this.data("hoveringPopover", true);
// If it still waiting to determine if it can be hovered, don't allow other handlers
if ($this.data("waitingForPopoverTO")) {
e.stopImmediatePropagation();
}
},
hide: function (e) {
var $this = $(this);
// If timeout was reached, allow hide to occur
if ($this.data("forceHidePopover")) {
$this.data("forceHidePopover", false);
return true;
}
// Prevent other `hide` handlers from executing
e.stopImmediatePropagation();
// Reset timeout checker
clearTimeout($this.data("popoverTO"));
// No longer hovering popover
$this.data("hoveringPopover", false);
// Flag for `show` event
$this.data("waitingForPopoverTO", true);
// In 1500ms, check to see if the popover is still not being hovered
$this.data("popoverTO", setTimeout(function () {
// If not being hovered, force the hide
if (!$this.data("hoveringPopover")) {
$this.data("forceHidePopover", true);
$this.data("waitingForPopoverTO", false);
$this.popover("hide");
}
}, 1500));
// Stop default behavior
return false;
}
});
DEMO: http://jsfiddle.net/L4Hc2/
Кажется, нет ничего встроенного для popover для нужной вам функции, так что это то, что я придумал:)
Хорошо, что он позволяет обработчикам выполнять, если они действительно должны - если popover фактически скрывается или фактически отображается. Кроме того, каждый экземпляр popover уникален друг от друга, поэтому глобальная хитрость не происходит.