繁体   English   中英

向下滚动“向上滑动”导航菜单,并在向上滚动时立即显示

[英]“slide up” nav menu on scroll-down, and appear as soon as scroll up

我希望我的导航菜单在向下滚动时立即向上滑动到某个水平,并在向上滚动时重新出现。 我希望它与以下菜单完全相同: http : //www.defringe.com/如果您注意到,当我们向下滑动时,我们仍然可以注意到菜单的提示。

现在,到目前为止,我能找到的是一个完全隐藏菜单的代码。 这是我的代码:

HTML:

<header id="header-wrap">
<nav id="topnav">
    <ul>
      <li>point1</li>
      <li>point2</li>
      <li>point3</li>
      <li>point4</li>
    </ul>
</nav>

CSS:

#topnav{
position:absolute;
margin:auto;
padding-top:20px;
height:60px;
width:576px;
bottom: 0;}

#header-wrap{
background:#f1f2f2;
height:60px;
position:fixed;
width:100%;}

jQuery的:

 $(function(){
    $('header').data('size','big');
   var previousScroll = 0;
    headerOrgOffset = $('#topnav').height()

$('#header-wrap').height($('#topnav').height());
});

$(window).scroll(function () {
    var currentScroll = $(this).scrollTop();
    if (currentScroll > headerOrgOffset) {
        if (currentScroll > previousScroll) {
            $('#header-wrap').slideUp("fast");
        } else {
            $('#header-wrap').slideDown("fast");
        }
    } 
    previousScroll = currentScroll;
});

谢谢!

在这种情况下,您不想使用slideUp / slideDown,而是构建自己的功能,该功能仅将菜单滑动至-margin

$(window).scroll(function () {
var currentScroll = $(this).scrollTop();
if (currentScroll > headerOrgOffset) {
    if (currentScroll > previousScroll) {
        // Say the menu height is 100px
        $('#header-wrap').css("margin-top", "-90px");
    } else {
        $('#header-wrap').css("margin-top", "0");
    }
} 
previousScroll = currentScroll;
});

显然,您需要正确设置菜单格式,进行修复等,但这应该可以解决问题。 如果您不确定如何使它工作,请告诉我,我可以为您完全做到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM