2014-01-13 162 views
1

我所试图做的如何,一旦你按下另一个按钮

关闭了辅助按钮股利和模仿从第一按钮了slideDown脚本了slideDown一个固定的股利。

一旦页脚按钮被按下它通过推动头向上显示我隐而未现的div (#footerPanel)问题

。一旦您再次单击页脚,它将关闭面板并将标题滑回原位。

一旦您将鼠标悬停在站点导航将显示的按钮上(不包括在JSFiddle中),菜单按钮将如下工作。通过这样做,我希望能够关闭#footerPanel并使标题向下滑动,模仿页脚按钮的关闭功能。

现在发生的事情是,当我点击菜单#footerPanel滑下来,但留在标题卡在推动它的位置。另外,当您移动鼠标时,div滑回。

我该如何解决这个问题?我尝试了一些解决方案,但他们似乎都有相同的结果。

JS的

$('#more').toggle(function(){ 
    //show its submenu 
$('#footerPanel').slideDown(500); 
$(this).parent().parent().animate({'bottom': "+=400"}, 500); 
    }, 
function() { 
    //hide its submenu 
$('#footerPanel').slideUp(500);  
$(this).parent().parent().animate({'bottom': "-=400"}, 500);    
    }); 
$(document).ready(function(){ 
$('#menu').hover(function(){ 
$("#footerPanel").slideToggle(); 
    }); 
}); 

JSFiddle

回答

1

更新小提琴:http://jsfiddle.net/9s33F/5/

我想我有你在找什么。我添加了以下内容作为打开菜单时animate函数完成时的回调。

function() { 
    $(this).addClass('open'); 
} 

然后在菜单中单击处理程序中添加以下语句if

if ($(this).closest('header').is('.open')) { 
    $('header').animate({'bottom': "-=400"}); 
} 

此外,你的代码会看起来更干净,是如果你使用.closest(),而不是.parent().parent()等较少。

jQuery.closest:http://api.jquery.com/closest/

+0

这个完美的作品,但如果我改变功能从点击到悬停时,#footerPanel滚动备份@Neil基斯特纳 – bigant841

+0

@ bigant841我在我的答案更新我的jsfiddle。我希望这是你正在寻找的。 –

+0

完美谢谢@尼尔·基斯特纳 – bigant841

相关问题