我会这样做:
首先,我在这里使用$(nav) 选择器,但您可以先将其调整为您的代码。
此外,您需要输入菜单:position: relative; 或 position: absolute;
让它滑出:
$(nav).animate({"top":$(nav).height() * -1},"slow");
让它滑入:
$(nav).animate({"top":0},"slow");
如果你想在 3 秒后弹出,我们开始:
function MenuOut()
{
/* The sample code I put on top */
$(nav).animate({"top":$(nav).height() * -1},"slow");
}
然后你把它放在你的 Js 页面上:
/* This will run once the document is ready */
$(function()
{
setTimeout("MenuOut",3000); /* 3000 represent 3000 milliseconds, so 3 seconds */
});
现在是按钮:
function MenuIn()
{
$(nav).animate({"top":0},"slow");
}
然后你像这样将它绑定到你的按钮:
$('#theButton').on(
{
click: function()
{
/* Hide the button, and then show up the menu */
$(this).animate({"top":$(this).height() * -1},"slow",function()
{
/* I putted this in a callback function, so the 2 animations will be one after the other, not at the same time ! */
MenuIn();
});
}
});