回答編集履歴

1

コメントからの追加回答です

2019/01/11 12:00

投稿

akihiro3
akihiro3

スコア955

test CHANGED
@@ -169,3 +169,253 @@
169
169
 
170
170
 
171
171
  ```
172
+
173
+
174
+
175
+ 修正
176
+
177
+ ---
178
+
179
+ jquery使える場合、これでどうでしょうか?
180
+
181
+ ```html
182
+
183
+ <!doctype html>
184
+
185
+ <html>
186
+
187
+ <head>
188
+
189
+ <meta charset="UTF-8">
190
+
191
+ <title>sample</title>
192
+
193
+ <link rel="stylesheet" href="ファイル名.css">
194
+
195
+ <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script>
196
+
197
+ </head>
198
+
199
+ <body>
200
+
201
+ <header>
202
+
203
+ <h1>header</h1>
204
+
205
+ </header>
206
+
207
+ <main>
208
+
209
+ <aside>
210
+
211
+ <div class="inner">
212
+
213
+ sidebar
214
+
215
+ </div>
216
+
217
+ </aside>
218
+
219
+ <article>
220
+
221
+ <div class="content">
222
+
223
+ <section>
224
+
225
+ section-1
226
+
227
+ </section>
228
+
229
+ <section>
230
+
231
+ section-2
232
+
233
+ </section>
234
+
235
+ <section>
236
+
237
+ section-3
238
+
239
+ </section>
240
+
241
+ <section>
242
+
243
+ section-4
244
+
245
+ </section>
246
+
247
+ </div>
248
+
249
+ </article>
250
+
251
+ </main>
252
+
253
+ <footer>
254
+
255
+ footer
256
+
257
+ </footer>
258
+
259
+ <script>
260
+
261
+ (function() {
262
+
263
+ var asideHeight = $('aside').outerHeight();
264
+
265
+
266
+
267
+ $(window).scroll(function() {
268
+
269
+ var scroll = $(window).scrollTop();
270
+
271
+ var footerTop = $('footer').offset().top;
272
+
273
+ var windowHeight = $(window).height();
274
+
275
+
276
+
277
+ if (scroll <= 50) {
278
+
279
+ $('aside').css({
280
+
281
+ top:50 - scroll,
282
+
283
+ height:asideHeight + scroll
284
+
285
+ });
286
+
287
+ }
288
+
289
+
290
+
291
+ if(scroll >= footerTop - windowHeight) {
292
+
293
+ $('aside').css({height:windowHeight - scroll + footerTop - windowHeight});
294
+
295
+ }
296
+
297
+
298
+
299
+ })
300
+
301
+
302
+
303
+ })();
304
+
305
+ </script>
306
+
307
+
308
+
309
+ </body>
310
+
311
+ </html>
312
+
313
+ ```
314
+
315
+ ```css
316
+
317
+ * {
318
+
319
+ margin: 0;
320
+
321
+ padding: 0;
322
+
323
+ }
324
+
325
+
326
+
327
+ html,body {
328
+
329
+ height: 100%;
330
+
331
+ }
332
+
333
+
334
+
335
+ main {
336
+
337
+ display: flex;
338
+
339
+ }
340
+
341
+
342
+
343
+ article {
344
+
345
+ background: #afafaf;
346
+
347
+ width: calc(100% - 250px);
348
+
349
+ margin-left: 250px;
350
+
351
+ }
352
+
353
+
354
+
355
+ header {
356
+
357
+ background: #00f;
358
+
359
+ width: 100%;
360
+
361
+ height: 50px;
362
+
363
+ }
364
+
365
+
366
+
367
+ section {
368
+
369
+ border: 5px solid #000;
370
+
371
+ height: 200px;
372
+
373
+ margin-bottom: 10px;
374
+
375
+ }
376
+
377
+
378
+
379
+ aside {
380
+
381
+ background: #f00;
382
+
383
+ width: 250px;
384
+
385
+ height: calc(100% - 50px);
386
+
387
+ position: fixed;
388
+
389
+ top: 50px;
390
+
391
+ bottom: 50px;
392
+
393
+ overflow-y: scroll;
394
+
395
+ }
396
+
397
+
398
+
399
+ .inner {
400
+
401
+ background: #fff;
402
+
403
+ height: calc(100% + 200px);
404
+
405
+ margin: 50px 10px;
406
+
407
+ }
408
+
409
+
410
+
411
+ footer{
412
+
413
+ background: #333;
414
+
415
+ width: 100%;
416
+
417
+ height: 50px;
418
+
419
+ }
420
+
421
+ ```