Search code examples
javascriptjquerycsshovertooltip

Jquery Tooltip with hover


i have a small Tooltip Script when the user hover a block the Tooltip will be shown and if the user leave the block the tooltip is hidden.

But i want also when the user hover over the tooltip the tooltip stay until the user leaves the tooltip or the hover block.

here is my javascript without the hover over the Tooltip:

$( "#hover, .tooltip" ).on('mouseenter', function() { 
   $( ".tooltip" ).fadeToggle( 400, function() {
       // Animation complete.
    });
});

$( ".tooltip, #hover" ).on('mouseleave', function() {
      $( ".tooltip" ).fadeToggle( 400, function() {
         // Animation complete.
      });
});

Here is a small Fiddle without the second part: http://jsbin.com/vocirucawoje/1/edit


Solution

  • use stop() to stop the animation.

    $( "#hover, .tooltip" ).on('mouseenter', function() { 
       $( ".tooltip" ).stop().fadeToggle( 400, function() {
           // Animation complete.
        });
    });
    
    $( ".tooltip, #hover" ).on('mouseleave', function() {
          $( ".tooltip" ).stop().fadeToggle( 400, function() {
             // Animation complete.
          });
    });