【发布时间】:2019-01-26 20:48:23
【问题描述】:
在下面的 sn-p 中,我有一个支持 Hover 和 Click 模式的 Bootstrap Popover。单击时,窗口保持打开状态,并且应在 (1) 自单击(再次链接)或 (2) 任何外部单击时关闭。
问题:外部点击后,弹出框进入“当前打开”模式。这意味着如果您再次将鼠标悬停在它上面,窗口就会被卡住并且不会消失。应该发生的是,在外部单击之后,当您再次将鼠标悬停在它上面时,您会恢复到原始的悬停和消失模式。此处预期的行为与在内部关闭单击后悬停时相同,这是原始状态。我是不是忘记了什么?
$('#linkPopover').popover({
trigger: 'hover click',
content: 'This is my content',
title: 'TITLE'
});
// -----------------
// Just with the above (and no other code), the Hover and Click-Toggle
// works within the SAME Popover window,
// but now I need to also remove the visible Popover on ANY CLICK OUTSIDE.
// However, although the below works, *after* clicking outside the Popover is in the CLICKED
// mode i.e. it doesn't hover anymore
$('body').on('click', function(e) {
$('[data-toggle="popover"]').each(function () {
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
// From outside click with the popover open, need to hide
$(this).popover('hide');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<a id="linkPopover" data-toggle="popover">POPOVER</a>
<br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/>
End of body
【问题讨论】:
标签: jquery twitter-bootstrap twitter-bootstrap-3