[英]Keep Twitter Bootstrap Tooltip open on mouseleave
对于特定情况和元素,我需要默认显示 Bootstrap 工具提示(一旦页面加载)并始终保持打开状态(即使在鼠标悬停和鼠标悬停时)。
这是我用来在元素上默认打开工具提示的代码:
$('#myelement').tooltip('show');
现在我不确定如何防止/禁用鼠标悬停和鼠标移出工具提示的默认操作。 任何的想法?
提前致谢!
找到解决方案。 手动触发器可以解决问题 - 这是更新的代码:
$('.taskTooltip').tooltip({trigger: 'manual'}).tooltip('show');
在显示后使用 unbind() :它将删除所有事件处理程序,因此工具提示不会在鼠标离开时隐藏
$(".circle").tooltip("show"); $(".circle").unbind();
.circle{ margin-left:100px; margin-top:80px; width:10px; height:10px; background-color:#0088ff; border-radius:50%; border:1px solid #ff8800; }
<!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!-- Latest compiled JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="circle" data-toggle="tooltip" data-placement="top" title="Hello World !"></div>
你也可以试试这个。
jsfiddle: https ://jsfiddle.net/shuNaka/o1ncd6r7/
js:
$('.switch').on('click touch', function (e) {
$('.tltip-element').not($(this).parents('.tltip-wrapper').find('.tltip-element')).fadeOut('fast');
$(this).parents('.tltip-wrapper').find('.tltip-element').fadeToggle('fast');
});
html:
<div>
<div class="tltip-wrapper">
<a href="#" class="switch">
click me 1 </a>
<div class="tltip-element" style="display: block;">
<div class="tltip-content">
<span>
test_1
</span>
<span class="">
test_2
</span>
</div>
</div>
</div>
</div>
css:
.tltip-wrapper {
position: relative;
cursor: default;
}
.tltip-wrapper .tltip-element {
color: #525252;
background-color: rgba(255, 255, 255, 0.8);
box-shadow: 0px 6px 12px rgba(155, 183, 182, 0.4);
border: solid 1px #83A7AD;
border-radius: 3px;
padding: 12px 12px 12px 12px;
font-size: 12px;
text-align: left;
display: none;
position: absolute;
left: 10%;
top: -10%;
}
.tltip-wrapper .tltip-element .tltip-content {
line-height: 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.