打开画布菜单时,固定的顶栏会移动到页面顶部

时间:2015-03-27 15:25:11

标签: jquery mmenu

当画布外的mmenu打开时,有没有办法让固定的顶杆保持原位?

滚动页面后,当关闭画布菜单时,固定的顶栏会消失。

小提琴示例:http://jsfiddle.net/sojourner7/yxcLhp6g/1/

   $(function() {
    $('nav#menu').mmenu({
        "offCanvas": {
            "position": "left"
        }
    });
});
html, body
{
	padding: 0;
	margin: 0;
}
body
{
	background-color: #fff;
	font-family: Arial, Helvetica, Verdana;
	font-size: 14px;
	line-height: 22px;
	color: #666;
	position: relative;
	-webkit-text-size-adjust: none;
}
body *
{
	text-shadow: none;
}
h1, h2, h3, h4, h5, h6
{
	line-height: 1;
	font-weight: bold;
	margin: 20px 0 10px 0;
}
h1, h2, h3
{
	font-size: 18px;
}
h4, h5, h6
{
	font-size: 16px;
}
p
{
	margin: 0 0 10px 0;
}
a, a:link, a:active, a:visited, a:hover
{
	color: inherit;
	text-decoration: underline;
}

nav:not(.mm-menu)
{
	display: none;
}

.header,
.content,
.footer
{
	text-align: center;
}
.header,
.footer
{
	background: #777;
	font-size: 16px;
	font-weight: bold;
	color: #fff;
	line-height: 40px;


	-moz-box-sizing: border-box;
	box-sizing: border-box;	
	width: 100%;
	height: 40px;
	padding: 0 50px;
}
.header.fixed
{
	position: fixed;
	top: 0;
	left: 0;
}
.footer.fixed
{
	position: fixed;
	bottom: 0;
	left: 0;
}
.header a
{
	background: center center no-repeat transparent;
	background-image: url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADhJREFUeNpi/P//PwOtARMDHQBdLGFBYtMq3BiHT3DRPU4YR4NrNAmPJuHRJDyahEeT8Ii3BCDAAF0WBj5Er5idAAAAAElFTkSuQmCC );

	display: block;
	width: 40px;
	height: 40px;
	position: absolute;
	top: 0;
	left: 10px;
}
.menutrigger a
{
	background: center center no-repeat transparent;
	background-image: url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADhJREFUeNpi/P//PwOtARMDHQBdLGFBYtMq3BiHT3DRPU4YR4NrNAmPJuHRJDyahEeT8Ii3BCDAAF0WBj5Er5idAAAAAElFTkSuQmCC );

	display: block;
	width: 40px;
	height: 40px;
	background-color:#ccc;
}
.content
{
	padding: 50px 50px 50px 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://www.geneva-college.com/geneva-responsive/mmenu-geneva/src/js/jquery.mmenu.min.all.js"></script>
<link type="text/css" rel="stylesheet" href="http://www.geneva-college.com/geneva-responsive/mmenu-geneva/src/css/jquery.mmenu.all.css" />


<div id="page">
    <div class="header fixed">	<a href="#menu"></a>
Demo</div>
    <div class="content">
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>
        <p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.</p>
        <p>Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p>
        <p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus.</p>
        <p>Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>
        <br />
    </div>
    <nav id="menu">
        <p>anything can go here</p>
        <ul>
            <li><a href="#">Home</a>
            </li>
            <li><a href="#about">About us</a>

                <ul>
                    <li><a href="#about/history">History</a>
                    </li>
                    <li><a href="#about/team">The team</a>

                        <ul>
                            <li><a href="#about/team/management">Management</a>
                            </li>
                            <li><a href="#about/team/sales">Sales</a>
                            </li>
                            <li><a href="#about/team/development">Development</a>
                            </li>
                        </ul>
                    </li>
                    <li><a href="#about/address">Our address</a>
                    </li>
                </ul>
            </li>
            <li><a href="#contact">Contact</a>
            </li>
        </ul>
    </nav>
</div>

1 个答案:

答案 0 :(得分:2)

你正在使用bootstrap吗?我遇到了同样的问题,但我将“navbar-fixed-top”类添加到我的标题中并且它有效。注意,我也使用mmenu的附加FixedTop。您可以在此处找到该信息:http://mmenu.frebsite.nl/documentation/addons/fixed-elements.html

希望这会有所帮助。