不能让jquery悬停与.live()一起工作

Har*_*ldo 2 jquery

第二个功能不起作用?

$('.edit_hover').live('hover',
    function(e){        
        $(this).stop();
        var half_width = ($(this).css('width').slice(0, -2))/2;
        var half_height = ($(this).css('height').slice(0, -2))*0.3;
        console.log(half_width);
        var top = ($(this).position().top) + half_height;
        var left = ($(this).position().left) + half_width;
        $('#edit_hover').css('top', top).css('left', left).fadeIn(300);
        //add overlay
        $(this).css('position', 'relative').append('<div class="edit_overlay" style="position: absolute; top:0px; left:0px; height:100%; width: 100%; background: #999; opacity: 0.5;"></div> ')
    },
    function(){
        $(this).stop();
        $(this).find('.edit_overlay').remove();
        $('#edit_hover').fadeOut(300);
    }); 
Run Code Online (Sandbox Code Playgroud)

Fel*_*ing 11

live()只需要一个处理程序,所以你不能使用hover(在1.4.1之前).无论如何,这仅仅是一个快捷方式mouseentermouseleave.使用这些事件绑定到:

$('.edit_hover')
.live('mouseenter',function(){})
.live('mouseleave',function(){}); 
Run Code Online (Sandbox Code Playgroud)

或者从jQuery 1.4.1开始:

$('.edit_hover').live('hover', function(event) {
  if (event.type == 'mouseenter') {
    // first function here
  } else {
    // second function here
  }
});
Run Code Online (Sandbox Code Playgroud)