0

就像在 Pinterest 应用程序中一样,当我向下/向上滚动时,我希望我的顶部导航栏向上/向下滑动,同时我的底部工具栏向下/向上滑动。

现在,我已经设法让我的顶部导航栏在使用下面的代码向上/向下滚动时隐藏和显示。我试图弄清楚如何使用底部工具栏同时做相反的事情,但我就是无法让它工作!

我对此很陌生,所以任何建议都将不胜感激!

jQuery:

$(document).ready(function(){

var previousScroll = 0,
    headerOrgOffset = $('#header').height();

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

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

1 回答 1

1

基于您在 jsfiddle 中提供的结构:

--HTML

<div id="header-wrap">
    <div id="header" class="clear">
        <nav><h1>Header</h1>another line<br/>another line
        </nav>
    </div>
</div>
<div id="footer-wrap">
    <div id="footer" class="clear">
        <nav><h1>Footer</h1>another line<br/>another line
        </nav>
    </div>
</div>

--CSS:

body {
    height: 1000px;
}

#header, #footer {
    width: 100%;
    height: 120px;
    /*position: absolute;*/
    background-color: #e0e0e0;
}

#header {
    top: -20px;
    position: relative;
}

#header-wrap, #footer-wrap {
    width: 100%;
    position: fixed;
    padding: 0px;
    /*background-color: #e0e0e0;*/
}

#header-wrap {
    top: 0px; 
}

#footer-wrap {
    bottom: 0px; 
}

--JS

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

    //$('#header-wrap').height($('#header').height());

    $(window).scroll(function () {
        var currentScroll = $(this).scrollTop();
        if (currentScroll > headerOrgOffset) {
            if (currentScroll > previousScroll) {
                $('#header').slideUp("slow");
                $('#footer').slideDown("slow");
            } else {
                $('#header').slideDown("slow");
                $('#footer').slideUp("slow");
            }
        } 
        previousScroll = currentScroll;
    });
});
于 2013-09-30T22:09:16.703 回答