I'm showing a jQuery UI Tooltip right in the middle of my element, when hovering. But the tooltip itself disappears when hovering over it. (propagation
problem)
Element:
With tooltip:
So, when I then hover the tooltip itself, it disappears, due to a propagation problem, I suppose.
HTML:
<div class="bar-wrapper">
<label class="bar-lbl active one" title="2013"><span>2013</span></label>
<div class="bar" data-percent="90"></div>
<div class="bar-rest-overlay" data-percent="10"></div>
</div>
<div class="bar-wrapper">
<label class="bar-lbl active one" title="2014"><span>2014</span></label>
<div class="bar" data-percent="80"></div>
<div class="bar-rest-overlay" data-percent="20"></div>
</div>
Current code:
$('.bar-lbl').tooltip(
{
tooltipClass: 'bar-tooltip',
position:
{
my: 'center',
at: 'center'
}
});
Partial fix (but leaves tooltips permanently visible):
$('.bar-lbl').on('mouseleave',
function(e)
{
e.stopImmediatePropagation();
}).tooltip(
{
tooltipClass: 'bar-tooltip',
position:
{
my: 'center',
at: 'center'
}
});
Not working:
$('body').on('hover', '.ui-tooltip',
function(e)
{
e.stopImmediatePropagation();
});
UPDATE: Thanks to Trevor, I came to a close-solution. (it still leaves the last hovered tooltip visible when hovering out):
It seems, when hovering out the tooltip itself, it hides. But hovering out of the .bar-lbl
element, the tooltip stays visible, unless I hover another .bar-lbl
element.
The problem is in the on('mouseleave')
event on my .bar-lbl
. I need both lines, but they interfere with each other. (see comments)
$('.bar-lbl').on('mouseenter',
function(e)
{
$('.bar-lbl').not($(this)).tooltip('close'); // Close all other tooltips
}).on('mouseleave',
function(e)
{
e.stopImmediatePropagation(); // keeps tooltip visible when hovering tooltip itself
$('.bar-lbl').tooltip('close'); // I need this, but it breaks the line above, causing the tooltip to flicker
}).tooltip(
{
tooltipClass: 'bar-tooltip',
position:
{
my: 'center',
at: 'center'
}
});
$('body').on('mouseleave', '.ui-tooltip',
function(e)
{
$('.bar-lbl').tooltip('close');
});