回答編集履歴
1
コメントからの追加回答です
answer
CHANGED
@@ -83,4 +83,129 @@
|
|
83
83
|
height: 100px;
|
84
84
|
}
|
85
85
|
|
86
|
+
```
|
87
|
+
|
88
|
+
修正
|
89
|
+
---
|
90
|
+
jquery使える場合、これでどうでしょうか?
|
91
|
+
```html
|
92
|
+
<!doctype html>
|
93
|
+
<html>
|
94
|
+
<head>
|
95
|
+
<meta charset="UTF-8">
|
96
|
+
<title>sample</title>
|
97
|
+
<link rel="stylesheet" href="ファイル名.css">
|
98
|
+
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script>
|
99
|
+
</head>
|
100
|
+
<body>
|
101
|
+
<header>
|
102
|
+
<h1>header</h1>
|
103
|
+
</header>
|
104
|
+
<main>
|
105
|
+
<aside>
|
106
|
+
<div class="inner">
|
107
|
+
sidebar
|
108
|
+
</div>
|
109
|
+
</aside>
|
110
|
+
<article>
|
111
|
+
<div class="content">
|
112
|
+
<section>
|
113
|
+
section-1
|
114
|
+
</section>
|
115
|
+
<section>
|
116
|
+
section-2
|
117
|
+
</section>
|
118
|
+
<section>
|
119
|
+
section-3
|
120
|
+
</section>
|
121
|
+
<section>
|
122
|
+
section-4
|
123
|
+
</section>
|
124
|
+
</div>
|
125
|
+
</article>
|
126
|
+
</main>
|
127
|
+
<footer>
|
128
|
+
footer
|
129
|
+
</footer>
|
130
|
+
<script>
|
131
|
+
(function() {
|
132
|
+
var asideHeight = $('aside').outerHeight();
|
133
|
+
|
134
|
+
$(window).scroll(function() {
|
135
|
+
var scroll = $(window).scrollTop();
|
136
|
+
var footerTop = $('footer').offset().top;
|
137
|
+
var windowHeight = $(window).height();
|
138
|
+
|
139
|
+
if (scroll <= 50) {
|
140
|
+
$('aside').css({
|
141
|
+
top:50 - scroll,
|
142
|
+
height:asideHeight + scroll
|
143
|
+
});
|
144
|
+
}
|
145
|
+
|
146
|
+
if(scroll >= footerTop - windowHeight) {
|
147
|
+
$('aside').css({height:windowHeight - scroll + footerTop - windowHeight});
|
148
|
+
}
|
149
|
+
|
150
|
+
})
|
151
|
+
|
152
|
+
})();
|
153
|
+
</script>
|
154
|
+
|
155
|
+
</body>
|
156
|
+
</html>
|
157
|
+
```
|
158
|
+
```css
|
159
|
+
* {
|
160
|
+
margin: 0;
|
161
|
+
padding: 0;
|
162
|
+
}
|
163
|
+
|
164
|
+
html,body {
|
165
|
+
height: 100%;
|
166
|
+
}
|
167
|
+
|
168
|
+
main {
|
169
|
+
display: flex;
|
170
|
+
}
|
171
|
+
|
172
|
+
article {
|
173
|
+
background: #afafaf;
|
174
|
+
width: calc(100% - 250px);
|
175
|
+
margin-left: 250px;
|
176
|
+
}
|
177
|
+
|
178
|
+
header {
|
179
|
+
background: #00f;
|
180
|
+
width: 100%;
|
181
|
+
height: 50px;
|
182
|
+
}
|
183
|
+
|
184
|
+
section {
|
185
|
+
border: 5px solid #000;
|
186
|
+
height: 200px;
|
187
|
+
margin-bottom: 10px;
|
188
|
+
}
|
189
|
+
|
190
|
+
aside {
|
191
|
+
background: #f00;
|
192
|
+
width: 250px;
|
193
|
+
height: calc(100% - 50px);
|
194
|
+
position: fixed;
|
195
|
+
top: 50px;
|
196
|
+
bottom: 50px;
|
197
|
+
overflow-y: scroll;
|
198
|
+
}
|
199
|
+
|
200
|
+
.inner {
|
201
|
+
background: #fff;
|
202
|
+
height: calc(100% + 200px);
|
203
|
+
margin: 50px 10px;
|
204
|
+
}
|
205
|
+
|
206
|
+
footer{
|
207
|
+
background: #333;
|
208
|
+
width: 100%;
|
209
|
+
height: 50px;
|
210
|
+
}
|
86
211
|
```
|