I need to add a predelay on my jQuery UI tooltips. I am using the most recent version (1.9) and would like the tips to open 2 seconds after they are hovered over.
I am calling the tips in my header using:
<script>
$(function() {
$( document ).tooltip({ predelay:2000,});
});
</script>
But when they are fired, they do not have any delay whatsoever... any help?
use this
$( "#elementid" ).tooltip({
show: {
effect: "slideDown",
delay: 250
}
});
I had the same problem but finally came up with this solution:
var opendelay = 500;
var closedelay = 500;
var target = $('.selector');
target.tooltip({ /* ... */ });
target.off('mouseover mouseout');
target.on('mouseover', function(event) {
event.stopImmediatePropagation();
clearTimeout(target.data('closeTimeoutId'));
target.data('openTimeoutId', setTimeout(function() { target.tooltip('open'); }, opendelay));
});
target.on('mouseout', function(event) {
event.stopImmediatePropagation();
clearTimeout(target.data('openTimeoutId'));
target.data('closeTimeoutId', setTimeout(function() { target.tooltip('close'); }, closedelay));
});
Essentially what it does is:
event.stopImmediatePropagation();
is only needed in some cases. eg. if you want the tooltip-element to stay visible while hovering IT (after it opened). If you want this, register the same hover events on the tooltip: target.tooltip({ open: function (event, ui) { ui.tooltip.hover(..., ...); } });
on
and off
.target
inside the event-functions by this
or $(this)
. But i'm not sure and haven't tried it; might not work after all.closeTimeoutId
or closedelay
and remove mouseout
in target.off('mouseover mouseout');
or set it to 0If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With