你好,我是一个新手想学习jQuery,并希望在用户停留在页面3/4秒后将导航菜单从页面顶部滑动出去。我可能会添加一个箭头按钮来使菜单下拉,但现在我只需要知道如何上下滑动它。我认为我还需要修改我的CSS才能使其正常工作。
非常感谢您提供的任何帮助或提示。
有关更多详细信息,请参见我的jsFiddle:http://jsfiddle.net/headex/tJNXD/
你好,我是一个新手想学习jQuery,并希望在用户停留在页面3/4秒后将导航菜单从页面顶部滑动出去。我可能会添加一个箭头按钮来使菜单下拉,但现在我只需要知道如何上下滑动它。我认为我还需要修改我的CSS才能使其正常工作。
非常感谢您提供的任何帮助或提示。
有关更多详细信息,请参见我的jsFiddle:http://jsfiddle.net/headex/tJNXD/
我会这样做:
首先,我在这里使用 $(nav)
选择器,但你可以根据自己的代码进行调整。
同时,你需要将菜单设置为:position: relative;
或者 position: absolute;
让它滑出来:
$(nav).animate({"top":$(nav).height() * -1},"slow");
$(nav).animate({"top":0},"slow");
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();
});
}
});
var timeout = null;
$('#masterNav').hover(function() {
clearTimeout(timeout);
}, function() {
timeout = setTimeout('$("#nav").slideUp(500)', 750);
});