JQuery - live ('hover') and mousemove

I have a little problem with the hover function with mousemove. But what is wrong?

working example -> http://www.jsfiddle.net/V9Euk/306/

$('.tip').live('hover', function(e)
{    
    if (e.type == 'mouseover')
    {
      $('#'+this.id+' .tooltip').show();
    }        
    if (e.type == 'mousemove')
    {
        alert('move');
         $('#'+this.id+' .tooltip').css({ left: e.pageX + 20, top: e.pageY + 20});
    }        
    if (e.type == 'mouseout')
    {
        $('.tooltip').hide();
    }    
});
+3
source share
3 answers

No events hover- you need to include all three events that you used, for example:

$('.tip').live('mouseout mousemove mouseover', function(e)

See jQuery documentations for several events at live():

$('.hoverme').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
    // do something on mouseover
  } else {
    // do something on mouseout
  }
});
+5
source

The problem is what is hover()mapped to mouseoverand `mouseleave), and not to the events you are using.

$("...").live("hover", function(e) {
  ...
});

is equivalent to:

$("...").live("mouseover mouseleave", function(e) {
  ...
});

If you want an event mousemove, you can also use:

$("...").live("hover mousemove", function(e) {
  ...
});
0
source

! , , .

.hover() mousemove, mouseenter/mouseleave.

mousemove,

$('.tip').live('mousemove', function(e) {
    // do stuff here
});
0

Source: https://habr.com/ru/post/1762128/


All Articles