jquery - 无法让 jquery 悬停与 .live() 一起使用

标签 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);
    }); 

最佳答案

live()仅需要一个处理程序,因此您无法使用 hover(1.4.1 之前)。无论如何,它只是 mouseentermouseleave 的快捷方式。使用这些事件绑定(bind)到:

$('.edit_hover')
.live('mouseenter',function(){})
.live('mouseleave',function(){}); 

或者从 jQuery 1.4.1 开始:

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

关于jquery - 无法让 jquery 悬停与 .live() 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638352/

相关文章:

javascript - 如果数据库中存在数据则显示警报图标 - JQuery AJAX

javascript - 如何访问放置在其旁边的元素?

javascript - 为什么 Plupload 中的 'add files' 按钮不会在最新的 Chrome 或 OS X 上的 FF 中触发?

javascript - 使用javascript重定向而不加载母版页

JQuery Animate 只运行一次

javascript - 无法从我的网络服务器读取本地服务器上的 json 文件

jquery - 如何使内容适合剩余高度

jquery - 在网页中创建由鼠标滚轮驱动的 "zoom in"和 "zoom out"

jquery - 我如何在 jQuery 中制作下拉菜单

php - 针对 MySQL 完整性约束违规的 jQuery 警报 (Laravel)