的jsfiddle: http://jsfiddle.net/kAYyR/
截图:
以下是工作原理:
- 按钮单击打开酥料饼
- 上点击外酥料饼关闭酥料饼
- 上点击关闭酥料饼
.close
按钮
但是...我不能让酥料饼当您再次单击原始按钮关闭。 取而代之的是酥料饼的闪烁,然后再打开。
自己复制它在这里 。
我怎样才能做到这一点?
HTML:
<button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
<div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
JS:
$('#popoverId').popover({
html: true,
title: "Popover Title",
content: function () {
return $('#popoverContent').html();
}
});
var isVisible = false;
var clickedAway = false;
$('.popoverThis').popover({
html: true,
trigger: 'manual'
}).click(function (e) {
$(this).popover('show');
$('.popover-content').append('<a class="close" style="position: absolute; top: 0; right: 6px;">×</a>');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function (e) {
if (isVisible & clickedAway) {
$('.popoverThis').popover('hide')
isVisible = clickedAway = false
} else {
clickedAway = true
}
});