第二个功能不起作用?
$('.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 之前)。无论如何,它只是 mouseenter
和 mouseleave
的快捷方式。使用这些事件绑定(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/