热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用粘性页眉和页脚切换侧栏-ToggleSidebarwithstickyheaderandfooter

Iwouldliketobeabletohaveasidebarthatcanbetoggledinandoutonabuttonpress.However

I would like to be able to have a side bar that can be toggled in and out on a button press. However, I'd want this sidebar to go with the main content of the page and fit between a sticky header and a sticky footer.

我希望能够有一个侧栏,可以按下按钮切换进出。但是,我希望这个侧边栏与页面的主要内容一起使用,并且适合粘性页眉和粘性页脚。

My problem is that when I scroll the sidebar stays fixed. I want the sidebar and page content to be able to scroll together and the header disappear. Then the page content will scroll while the header stays where it is. Then once the bottom of the page is reached the footer comes in which will shrink the bottom of the sidebar. If there is overflow in the side bar then the sidebar should be scrollable.

我的问题是当我滚动侧边栏时保持固定。我希望侧边栏和页面内容能够一起滚动,标题消失。然后页面内容将滚动,而标题保持原样。然后,一旦到达页面底部,页脚就会进入,这会缩小侧边栏的底部。如果侧栏中有溢出,则侧栏应该可滚动。

I have a nearly working example using bootstrap and simple-side bar template here: https://jsfiddle.net/co7080j6/. The only problem is that the side bar doesn't adjust it's position with the sticky header and footer.

我在这里使用bootstrap和简单的侧边栏模板有一个近乎工作的例子:https://jsfiddle.net/co7080j6/。唯一的问题是侧栏不能用粘性页眉和页脚调整它的位置。

The html I'm using is here:

我正在使用的html在这里:


 




Place sticky footer content here.

And besides bootstrap and simple sidebar (I removed z-index on the sidebar) I'm also I'm also using:

除了bootstrap和简单的侧边栏(我在侧边栏上删除了z-index)我也是我也在使用:

/*MY CSS*/
.container-full {
  margin: 0 auto;
  width: 100%;
}

html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  background-color: #333;
}

*I'd also like it if the header came into view any time the window scrolled up, but I think I can get that myself once this is resolved.

*如果在窗口向上滚动的时候标题进入视图我也会喜欢它,但是我认为一旦解决了这个问题我就能自己解决。

1 个解决方案

#1


1  

This is more of a CSS issue than anything. If you make the following changes to the CSS file, you get the functionality you desire.

这更像是一个CSS问题。如果对CSS文件进行以下更改,则可以获得所需的功能。

#sidebar-wrapper {
    position: absolute;
    height: 90%;
}

.sidebar-nav {
    position: fixed;
    top: 55px;
    left: 30px;
}

Also need to include a little extra JQuery to get around the fact that the sidebar-nav text doesn't hide when position is set to fixed.

还需要包含一些额外的JQuery来解决当位置设置为固定时侧边栏导航文本不隐藏的事实。

$(document).ready(function() {
    $('#menu-toggle').click(function() {
       $('.sidebar-nav').fadeToggle(300); 
    });
});

Here's a JSFiddle

这是一个JSFiddle

I'm not 100% sure you wanted the sidebar text to scroll or stay in place. If you want it to stay put, simply remove the .sidebar-nav CSS changes I made. And here's the JSFiddle for that.

我不是100%确定您希望侧边栏文本滚动或保持原位。如果你希望它保持不变,只需删除我所做的.sidebar-nav CSS更改。这是JSFiddle。


推荐阅读
author-avatar
牧羊人2602903895
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有