だから私はあなたの最善の策は、あなたがちょうど非常に簡単にモバイルのためにこれをカスタマイズするためにCSSを使用することができますので、実際にはこのためのstickyfillポリフィルとともに粘着性のCSSの位置を使用することだと思うし、また、あなたのヘッダーサイズを心配する必要はありません、それは同様にあなたのフッターのために停止します。
あなたは粘着性のCSSの位置について読むことができ、ここでhttps://www.sitepoint.com/css-position-sticky-introduction-polyfills/
だから私は私の漢に少し時間がありました私はちょっとしたものをまとめると思った。私はページ全体をコピーして貼り付けるだけで済むように思った。私はちょうどbootstrap、jquery、stickyfill polyfillのcdnにリンクしましたが、あなたはローカルのサーバ上でそれらを実行できるように、URLに行ってコピーすることができます。
ここで、それはそれはいくつかの違いは、コピーして自分のページに同じ見て、このページ全体を貼り付け、それは、あなたがあなたの好みに合わせてカスタマイズすることができますどのように機能するかを確認する必要があります:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<style>
body{padding-top:50px; overflow-x:hidden;}
#masthead{
min-height:200px;
padding:40px 0;
}
footer{
height:1000px;
background:#efefef;
margin-top:40px;
}
@media screen and (min-width:768px){
#sidebar-wrapper{
position: -webkit-sticky;
position: sticky;
top: 70px;
/*the following gives a smoother scrooll in webkit broswers*/
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.sidebar-toggle{display:none; }
}
@media screen and (max-width:768px){
#sidebar{
position:fixed;
top:20px;bottom:20px;right:-90%;left:auto;
width:90%;
background:#fff;
padding:20px;
-ms-transition: all 500ms ease-in-out;
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
-o-transition: all 500ms ease-in-out;
transition: all 500ms ease-in-out;
z-index:99999;
/*the following gives a smoother scrooll in webkit broswers*/
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.sidebar-open #sidebar{
right:0;
}
.sidebar-open .sidebar-overlay{
position:fixed;
top:0;left:0;
width:100%;
height:100%;
background:rgba(0,0,0,0.7);
z-index:9999;
}
#sidebar .sidebar-toggle{
width:100%;
height:50px;
border:none;
background:#efefef;
outline:0;
font-weight:bold;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/" class="navbar-brand">Bootply</a>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav pull-left">
<button type="button" class="btn btn-primary navbar-btn" data-toggle="modal" data-target="#mylinks">Links</button>
<button type="button" class="btn btn-danger navbar-btn" data-toggle="modal" data-target="#myModal">Open Small</button>
<button type="button" class="btn btn-primary btn-md navbar-btn" data-toggle="modal" data-target="#myModal">Open Small</button>
<button type="button" class="btn btn-danger btn-md navbar-btn" data-toggle="modal" data-target="#myModal">Open Small</button>
</ul>
<ul class="nav navbar-nav pull-right">
<li>
<a href="#sec">Get Started</a>
</li>
<li>
<a href="#sec">Edit</a>
</li>
<li>
<a href="#sec">Visualize</a>
</li>
<li>
<a href="#sec">Prototype</a>
</li>
</ul>
</nav>
</div>
</nav>
<div id="masthead">
<div class="container">
<div class="row">
<div class="col-md-7">
<h1>Bootstrap Sidebar
<p class="lead">With Css Sticky and Off Canvas</p>
</h1>
</div>
<div class="col-md-5">
<div class="well well-lg">
<div class="row">
<div class="col-sm-6">
<img src="http://placehold.it/180x100" class="img-responsive">
</div>
<div class="col-sm-6">
nothing here
</div>
</div>
</div>
</div>
</div>
</div><!--/container-->
</div><!--/masthead-->
<div class="container">
<div class="row">
<div class="col-sm-9">
<button type="button" class="btn btn-primary sidebar-toggle">Open Sidebar</button>
<h2 id="sec0">Content</h2>
<p>
At Bootply we like to build simple Bootstrap templates that utilize the code Bootstap CSS without a lot of customization. Sure you can
find a lot of Bootstrap themes and inspiration, but these templates tend to be heavy on customization.</p>
<hr>
<p>
Rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
Rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut!</p>
<h2 id="sec1">Content</h2>
<p>
Rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut.
</p>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><h3>Hello.</h3></div>
<div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pharetra varius quam sit amet vulputate.
Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Aenean sit amet felis
dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan.
Aliquam in felis sit amet augue.
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading"><h3>Hello.</h3></div>
<div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pharetra varius quam sit amet vulputate.
Quisque mauris augue, molestie tincidunt condimentum vitae, gravida a libero. Aenean sit amet felis
dolor, in sagittis nisi. Sed ac orci quis tortor imperdiet venenatis. Duis elementum auctor accumsan.
Aliquam in felis sit amet augue.
</div>
</div>
</div>
</div>
<hr>
<h2 id="sec2">Section 2</h2>
<p>
Rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut!
</p>
<div class="row">
<div class="col-md-4"><img src="http://placehold.it/300x300" class="img-responsive"></div>
<div class="col-md-4"><img src="http://placehold.it/300x300" class="img-responsive"></div>
<div class="col-md-4"><img src="http://placehold.it/300x300" class="img-responsive"></div>
</div>
<hr>
<h2 id="sec3">Section 3</h2>
<p>
Images are responsive sed @mdo but sum are more fun peratis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
</p>
<p>
Fos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
</p>
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
</p>
<h2 id="sec4">Section 4</h2>
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
</p>
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia cor magni dolores
eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit,
sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut.
</p>
</div>
<div class="sidebar-overlay"></div>
<div class="col-sm-3" id="sidebar-wrapper">
<ul class="nav nav-pills nav-stacked" id="sidebar">
<button class="sidebar-toggle">Close Sidebar</button>
<li class="active"><a href="#sec0">Section 0</a></li>
<li><a href="#sec1">Section 1</a></li>
<li><a href="#sec2">Section 2</a></li>
<li><a href="#sec3">Section 3</a></li>
<li><a href="#sec4">Section 4</a></li>
</ul>
</div><!--/left-->
</div>
</div>
<footer></footer>
<!-- JavaScripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stickyfill/1.1.4/stickyfill.min.js"></script>
<script>
$(document).ready(function(){
$('#sidebar-wrapper').Stickyfill();
});
$('body').scrollspy({ target: '#sidebar-wrapper', offset:70});
$('#sidebar a').click(function() {
if($('body').hasClass("sidebar-open")){
$('body').removeClass("sidebar-open");
}
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top- 50
}, 1000);
return false;
}
}
});
$('.sidebar-toggle, .sidebar-overlay').click(function(){
$('body').toggleClass("sidebar-open");
});
</script>
</body>
</html>
まず私はトグルにjqueryのを使用サイドバーのクラスは身体に開放されています。これにより、サイドバーの切り替えボタンがクリックされたときに、サイドバーとオーバーレイをカスタマイズすることができます。大きな画面では、サイドバーのラッパーにスティッキーな位置を使用することができます。スクロールするとスクロールしながらスクロールします。次に、polyfillはCSSの位置を固定していないブラウザを処理します。
あなたは問題が解決されるとそれ以外の質問はほとんど価値を持っている、あなたの質問にあなたのコードをポストする必要がhttps://github.com/wilddeer/stickyfill
を見つけて、ここポリフィルについて読むことができます。また、コンソールのエラーをチェックすることから始めてください。 – vanburen