带有粘性侧边栏的jPushMenu

时间:2014-10-22 15:22:52

标签: jquery menu fixed sidebar

我正在开发一个左侧有jPushMenu的投资组合网站,但内容中还包含一个粘性边栏。推送菜单无法推送"我的侧边栏因为它设置为position:fixed;在我的CSS中。

请原谅急于求成的JSFiddle,但我here正在与我合作。任何帮助将不胜感激!

<!-- Hidden drawer menu -->
<nav class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left">
    <a href="#" class="toggle-menu menu-left push-body hide-menu">Hide menu</a>
    <a href="#">Portfolio</a>
    <a href="#">Sourcing</a>
    <a href="#">About</a>
</nav>

<!--Fixed sidebar-->
<div class="info_sidebar">
    <a href="#" class="toggle-menu menu-left push-body show-menu dark">Show menu</a>

    <h1 class="project-title">East London</h1>
    <p>Pellentesque aliquam, lorem eu consequat mollis, ante nulla eleifend leo, id porta magna magna quis augue. Duis egestas neque id interdum accumsan. Maecenas a congue neque, in gravida turpis. Nullam posuere tellus eu pellentesque cursus. Integer vitae diam et metus luctus consequat. Nullam lectus leo, lobortis nec ultricies in, consequat a quam. Integer orci nisi, faucibus ut elit vel, mattis convallis enim. Nunc sed velit a ligula euismod vehicula.</p>
    <p>Nulla et efficitur tellus. Sed consequat ornare magna, ac vestibulum elit tempor vel. Fusce laoreet quam purus, et congue magna pellentesque mollis. Donec et vestibulum tellus. Aenean a eros eget quam accumsan posuere. Etiam eu accumsan odio. Sed porttitor quam non magna volutpat dapibus.</p>

    <div class="social_share">
        <ul>
            <li><a href="">Like</a></li>
            <li><a href="">Tweet</a></li>
            <li><a href="">Pin</a></li>
        </ul>
    </div>

        <div class="footer_nav">
            <div class="previous">< Previous</div>
            <div class="next">Next ></div>
        </div>
    </div><!--End of fixed sidebar-->

<!--Images-->
<div class="image_list">
   <img src="image.jpg" />
   <img src="image.jpg" />
   <img src="image.jpg" />
</div>

1 个答案:

答案 0 :(得分:0)

对任何有兴趣的人。我设法得到了答案。 Haven没有使用jPushMenu,而是使用纯CSS和一些jQuery来切换一些类。请参阅JSFiddle here

以下代码:

<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $(".button").click(function(){
    $("#wrapper").toggleClass("push");
  });
});

$(document).ready(function(){
  $(".button").click(function(){
    $("#menu").toggleClass("push");
  });
});
</script>

</head>

<body>

<style>

body, html {
    margin: 0;
    padding: 0;
}

#wrapper.normal {
    margin-left: 0;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;  
}

#wrapper.push {
    margin-left: 300px;
    overflow: hidden;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;  
}


#menu.normal {
    position: fixed;
    width: 300px;
    height: 100%;
    left: -300px;
    background-color: hsla(0,0%,80%,1.00);
    color: #0D0D0D;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;      
}

#menu.push {
    position: fixed;
    width: 300px;
    height: 100%;
    left: 0;
    background-color: hsla(0,0%,80%,1.00);
    color: #0D0D0D;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;      
}


#sidebar {
    position: fixed;
    width: 300px;
    padding: 50px;
    height: 100%;
    background-color:hsla(0,0%,94%,1.00);
}

#content {
    margin-left: 400px;
}
</style>

<!--Off canvas menu-->
<nav id="menu" class="normal">
    <a class="button" href="#">Hide menu</a>
    <ul>
        <li>Option 1</li>
        <li>Option 2</li>
        <li>Option 3</li>
    </ul>    
</nav>

<!--Page wrapper-->    
<div id="wrapper" class="normal">
    <div id="sidebar">
        <a class="button" href="#">Show menu</a>

        <h1>Project Title</h1>
        <p>Some content goes here.</p>
</div>

<div id="content">
    <img src="http://www.aviatorcameragear.com/wp-content/uploads/2012/07/placeholder.jpg"/>
    <img src="http://www.aviatorcameragear.com/wp-content/uploads/2012/07/placeholder.jpg"/>
    <img src="http://www.aviatorcameragear.com/wp-content/uploads/2012/07/placeholder.jpg"/>    
</div>
</div>
</body>
</html>