Muh*_*mbi 174 javascript jquery twitter-bootstrap
我正在使用Bootstrap的Popover构建一个网站,我无法弄清楚如何使鼠标悬停而不是点击.
我想要做的就是当有人在链接上盘旋而不是点击它时弹出窗口,当弹出窗口移开时弹出消失.文档说明可以使用data属性或jquery.因为我有多个弹出窗口,所以我宁愿用jquery做这件事.
Joã*_*lva 360
设置trigger的酥料饼来选择hover,而不是click,这是默认的.
这可以使用data-*标记中的任一属性来完成:
<a id="popover" data-trigger="hover">Popover</a>
Run Code Online (Sandbox Code Playgroud)
或者使用初始化选项:
$("#popover").popover({ trigger: "hover" });
Run Code Online (Sandbox Code Playgroud)
这是一个演示.
小智 32
我想补充一点,为了获取可访问性,我认为你应该添加焦点触发器:
即 $("#popover").popover({ trigger: "hover focus" });
Joh*_*ner 11
如果你想悬停弹出窗口本身,你必须使用手动触发器.
这就是我提出的:
function enableThumbPopover() {
var counter;
$('.thumbcontainer').popover({
trigger: 'manual',
animation: false,
html: true,
title: function () {
return $(this).parent().find('.thumbPopover > .title').html();
},
content: function () {
return $(this).parent().find('.thumbPopover > .body').html();
},
container: 'body',
placement: 'auto'
}).on("mouseenter",function () {
var _this = this; // thumbcontainer
console.log('thumbcontainer mouseenter')
// clear the counter
clearTimeout(counter);
// Close all other Popovers
$('.thumbcontainer').not(_this).popover('hide');
// start new timeout to show popover
counter = setTimeout(function(){
if($(_this).is(':hover'))
{
$(_this).popover("show");
}
$(".popover").on("mouseleave", function () {
$('.thumbcontainer').popover('hide');
});
}, 400);
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
if(!$(_this).is(':hover')) // change $(this) to $(_this)
{
$(_this).popover('hide');
}
}
}, 200);
});
}
Run Code Online (Sandbox Code Playgroud)
您描述的功能可以使用Bootstrap工具提示轻松实现.
<button id="example1" data-toggle="tooltip">Tooltip on left</button>
Run Code Online (Sandbox Code Playgroud)
然后为元素调用tooltip()函数.
$('#example1').tooltip();
Run Code Online (Sandbox Code Playgroud)
http://getbootstrap.com/javascript/#tooltips
| 归档时间: |
|
| 查看次数: |
265283 次 |
| 最近记录: |