Bootstrap 3 Tooltip Flickers
I have a Bootstrap 3 button with a tooltip. When clicking the button the tooltip shows and then fades out. When clicking a 2nd time the tooltip flickers and does not nicely fade ou
Solution 1:
You should use trigger: 'manual'
so you can control how the tooltip is shown or hidden.
$('[data-toggle="tooltip"]').tooltip({
trigger: 'manual',
placement: 'bottom'
});
function showTooltip(node) {
node.tooltip('show');
}
function hideTooltip(node) {
setTimeout(function() {
node.tooltip('hide');
}, 1000);
}
$('.btn').on('click', function() {
var node = $(this);
showTooltip(node);
hideTooltip(node);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<button type="button" class="btn btn-primary" data-title="Tooltip" data-toggle="tooltip">Click me</button>
Solution 2:
Here you with a solution
$('.btn').on('click', function() {
var node = $(this);
var msg = node.attr('data-title');
node.attr('data-original-title', msg)
.tooltip('show');
setTimeout(function() {
node.tooltip('hide');
}, 1000);
});
$('.btn').on('mouseleave', function() {
$(this).tooltip('hide');
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<button type='button' class='btn btn-primary' data-placement='bottom' data-title='Tooltip' data-toggle='tooltip' data-trigger='manual'>Click me</button>
Hope this will help you
Post a Comment for "Bootstrap 3 Tooltip Flickers"