[英]How do you make a fixed, responsive sidebar?
This website has a beautiful sidebar: http://thenextweb.com/ I know how to make a fixed sidebar in css, but making it stop scrolling at a certain point is where I'm lost. 这个网站有一个漂亮的侧边栏: http : //thenextweb.com/我知道如何在CSS中制作一个固定的侧边栏,但是让它在某个点停止滚动是我迷失的地方。 And making it disappear at a certain width is a media query I think?
我想让它以一定宽度消失是一种媒体查询吗?
Try this script 试试这个脚本
<script>
$(document).ready(function(){
$('#page').scroll(function(){
if(document.getElementById("page").scrollTop > 100) {
$('#sidebar').css("position","fixed");
}
});
});
Where page is the wrapper element 页面是包装元素
I made a CodePen with a sidebar that is fixed in its related container. 我制作了一个带有固定在其相关容器中的侧边栏的CodePen。
You can see it here: http://codepen.io/tomanagle/pen/vGaEvG 您可以在这里看到它: http : //codepen.io/tomanagle/pen/vGaEvG
As for making it disappear at a certain breakpoint. 至于使其在某个断点处消失。 Use a media query.
使用媒体查询。
@media screen and (max-width: 1280px){
aside{
display: none;
}
#article{
margin: auto;
float: none;
}
}
There is also a library you can use to make sticky sidebars: http://leafo.net/sticky-kit/ 您还可以使用一个库来制作粘性侧边栏: http : //leafo.net/sticky-kit/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.