我希望在悬停时显示一个弹出窗口,但只有当用户与其进行交互时才会保留(如果没有),它会在500ms后消失。
的Javascript
$(document).ready(function(){
$('[data-toggle="tooltip"]').popover({ title: 'Look! A bird!', html:true, delay: { show: 100, hide: 1000 } });
});
PHP
<button type="button" class="badge btn btn-default" data-trigger="click" data-toggle="tooltip" data-placement="top" data-html=true data-content="@foreach($tag->tracks as $track) <a href='/tracks/{{ $track->mdbid }}'>{{ $track->title }}</a> @endforeach">{{ $tag->tracks->count() }}</button>
忽略括号内的有趣代码(这是Laravel刀片语法)
的jsfiddle
我创建了这个JSFiddle虽然它不能正常工作(它在我的机器上)。我有延迟工作。但是,如果鼠标位于弹出窗口内,它仍然会消失。如何防止这种情况并使其仅在鼠标悬停在弹出框外时消失?
答案 0 :(得分:1)
这JSFiddle解决了它。
<强> HTML 强>
<p id='container'>
<button class='btn btn-primary btn-large' data-popover="true" data-html=true data-content="<a href='http://www.wojt.eu' target='blank' >click me, I'll try not to disappear</a>">hover here</button>
</p>
<强>的Javascript 强>
var originalLeave = $.fn.popover.Constructor.prototype.leave;
$.fn.popover.Constructor.prototype.leave = function(obj){
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
var container, timeout;
originalLeave.call(this, obj);
if(obj.currentTarget) {
container = $(obj.currentTarget).siblings('.popover')
timeout = self.timeout;
container.one('mouseenter', function(){
//We entered the actual popover – call off the dogs
clearTimeout(timeout);
//Let's monitor popover content instead
container.one('mouseleave', function(){
$.fn.popover.Constructor.prototype.leave.call(self, self);
});
})
}
};
$('body').popover({ selector: '[data-popover]', trigger: 'click hover', placement: 'auto', delay: {show: 50, hide: 400}});
<强> CSS 强>
#container {
text-align: center;
margin: 8em 3em;
}