我需要在jquery中重新绑定mouseout事件,因为当鼠标转到主div的子节点时(我已经将mouseout事件绑定了),会调用mouseout事件并且我不想要它。所以我这样做:
$('.div-hidden').live('mouseout', function (event) {
e = event.toElement || event.relatedTarget;
if (e.parentNode.parentNode == this || e == this || e.parentNode == this) {
return;
}
if ($(this).parent().css('overflow') == "visible") {
var parent_height = parseInt($(this).parent().parent().css('height').substr(0, $(this).css('height').length), 10);
$(this).parent().animate({
top: (parent_height - 40) + "px"
}, 500, function () {
$(this).css('overflow', 'hidden');
});
}
});
这适用于ie8 / 9和其他浏览器,但不适用于ie7。我也尝试用bind()更改live()但它不起作用。我该怎么办?
答案 0 :(得分:1)
似乎你想要mouseleave事件:
$('.div-hidden').live('mouseleave', function (event) {
if ($(this).parent().css('overflow') == "visible") {
var parent_height = parseInt($(this).parent().parent().css('height').substr(0, $(this).css('height').length), 10);
$(this).parent().animate({
top: (parent_height - 40) + "px"
}, 500, function () {
$(this).css('overflow', 'hidden');
});
}
});
你不应该使用.live
,除非你的jQuery版本是< 1.4.2或其他什么。
答案 1 :(得分:0)
在这种情况下,你最好使用mouseenter / mouseleave事件吗?