Javascript jquery-取消绑定不重新绑定

Javascript jquery-取消绑定不重新绑定,javascript,jquery,bind,unbind,Javascript,Jquery,Bind,Unbind,我有以下代码: $homeSlider.mouseenter(function() { console.log('enter'); $slideInfo.animate({ 'bottom': -slideInfoHeight + 'px' }); }); $homeSlider.mouseleave(function() { console.log('leave'); $slideInfo.animate({ 'botto

我有以下代码:

$homeSlider.mouseenter(function() {
    console.log('enter');
    $slideInfo.animate({
        'bottom': -slideInfoHeight + 'px'
    });
});
$homeSlider.mouseleave(function() {
    console.log('leave');
    $slideInfo.animate({
        'bottom': '0px'
    });
});
$slideInfo.mouseenter(function() {
    $homeSlider.unbind('mouseenter');
    $homeSlider.unbind('mouseleave');
});
$slideInfo.mouseleave(function() {
    $homeSlider.bind('mouseenter');
    $homeSlider.bind('mouseleave');
})

我的slideinfo div绝对位于主滑块div的顶部。如果在主滑块上滚动,则slideinfo会隐藏自己(-slideinfo高度),并在滚动时显示自己。如果将鼠标移到slideInfo div上,它将保持可见,并在您展开时保持可见。但是,当您在主幻灯片上回滚时,它不再隐藏幻灯片信息。我做错了什么?

我建议使用变量,而不是继续绑定和解除绑定:

var preventAnimation = false;
$homeSlider.mouseenter(function() {
    if (preventAnimation) return;
    console.log('enter');
    $slideInfo.animate({
        'bottom': -slideInfoHeight + 'px'
    });
});
$homeSlider.mouseleave(function() {
    if (preventAnimation) return;
    console.log('leave');
    $slideInfo.animate({
        'bottom': '0px'
    });
});
$slideInfo.mouseenter(function() {
    preventAnimation = true;
});
$slideInfo.mouseleave(function() {
    preventAnimation = false;
})

还有,你可以看看

未绑定的处理程序丢失。没有函数你不能简单地调用。啊-谢谢-是的,只需要添加函数