两个可滚动的div

时间:2012-11-16 04:56:20

标签: jquery html scrollbar

让我尽力解释我想要发生的事情,向我展示我希望能获得一些帮助的代码。

所以,我正试图从屏幕左侧做一个滑动导航UI(就像许多移动应用程序一样)。主要内容滑过,显示下方的导航菜单。

虽然在手机上的内容基本上完全不在屏幕上,但是在桌面上,很多页面仍然存在...我要为导航元素和主屏幕启用滚动(当屏幕移动时)过度)。我不知道是否需要一个jquery插件?如果是这样,那可能完全是针对不同的帖子。

无论如何,这是我的小提琴:http://jsfiddle.net/2vP67/6/

以下是帖子中的代码:

HTML

<div id='wrapper'>
    <div id='navWide'> </div>
    <div id='containerWide'> </div>
    <div id='containerTall'>
        <div id='container'>
            <div id='nav'>
                <div id='navNavigate'> Open Menu </div>
                <div id='navNavigateHide'> Close Menu </div>
            </div>
        </div>
    </div>
    <div id='sideContainerTall'>
        <div id='sideContainer'>
            <div id='sideNav'>Side Navigation </div>
        </div>
    </div>
</div>

CSS

#wrapper {
    width:100%;
    min-width:1000px;
    height:100%;
    min-height:100%;
    position:relative;
    top:0;
    left:0;
    z-index:0;
}
#navWide {
    color: #ffffff;
    background:#222222;
    width:100%;
    min-width:1000px;
    height:45px;
    position:fixed;
    top:0;
    left:0;
    z-index:100;
}
#containerWide {
    width:100%;
    min-width:1000px;
    min-height:100%;
    position:absolute;
    top:45px;
    z-index:100;
}
#containerTall {
    color: #000000;
    background:#dadada;
    width:960px;
    min-height:100%;
    margin-left:-480px;
    position:absolute;
    top:0;
    left:50%;
    z-index:1000;
}
/***** main container *****/

#container {
    width:960px;
    min-height:585px;
}
#nav {
    color: #ffffff;
    background:#222222;
    width:960px;
    height:45px;
    position:fixed;
    top:0;
    z-index:10000;
}
#navNavigate {
    background:yellow;
    font-size:10px;
    color:#888888;
    width:32px;
    height:32px;
    padding:7px 6px 6px 6px;
    float:left;
    cursor:pointer;
}
#navNavigateHide {
    background:yellow;
    font-size:10px;
    color:#888888;
    width:32px;
    height:32px;
    padding:7px 6px 6px 6px;
    float:left;
    cursor:pointer;
    display:none;
}
#sideContainerTall {
    background:#888888;
    width:264px;
    min-height:100%;
    margin-left:-480px;
    position:absolute;
    top:0;
    left:50%;
    z-index:500;
}
#sideContainer {
    width:264px;
    min-height:585px;
    display:none;
}
#sideContainerTall {
    background:#888888;
    width:264px;
    min-height:100%;
    margin-left:-480px;
    position:absolute;
    top:0;
    left:50%;
    z-index:500;
}
#sideContainer {
    width:264px;
    min-height:585px;
    display:none;
}
#sideNav {
    width:264px;
    height:648px;
    float:left;
}

的Javascript

$(document).ready(function() {

    $('div#navNavigate').click(function() {

        $('div#navNavigate').hide();

        $('div#navNavigateHide').show();

        $('div#sideContainer').show();

        $('div#containerTall').animate({
            'left': '+=264px'
        });
    });

    $('div#navNavigateHide').click(function() {

        $('div#navNavigate').show();

        $('div#navNavigateHide').hide();
        $('div#containerTall').animate({
            'left': '-=264px'
        }, function() {
            $('div#sideContainer').hide();
        });
    });

});

1 个答案:

答案 0 :(得分:1)

使用css,将其添加到#sideNav

overflow:auto;

如果您想强制滚动,无论内容是否表明:

overflow:scroll;

相关问题