teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードブロックに変更し、CSSを記述しました。consoleにエラーは出ておりません。

2018/08/28 05:38

投稿

cofcof
cofcof

スコア37

title CHANGED
File without changes
body CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  htmlの内容
4
4
  ------------------------
5
+
6
+ ```html
5
7
  <header>
6
8
  Position:fixedで固定されているヘッダーです。
7
9
  </header>
@@ -11,12 +13,14 @@
11
13
  </div>
12
14
  <main>
13
15
  以下コンテンツが入ります。
14
- ------------------------
16
+ ```
15
17
  これに対して、以下のようなjqueryを記述してみましたが、動きませんでした。
16
18
  具体的にはmainがページ上部まで来たらheaderにclass='bback'を付与して背景色を変更させようと考えていました。
17
19
 
18
20
  scriptの内容
19
21
  ------------------------
22
+
23
+ ```javascript
20
24
  $(function(){
21
25
  $(window).scroll(function() {
22
26
  var top_count = $(document).scrollTop();
@@ -29,6 +33,44 @@
29
33
  }
30
34
  });
31
35
  });
36
+ ```
37
+
38
+ cssの内容
39
+ ```css
40
+ header {
41
+ height: 50px;
42
+ position: fixed;
43
+ z-index: 1000;
44
+ width: 100%;
45
+ min-width: 320px;
46
+ top: 0;
47
+ left: 0;
48
+ }
49
+ header.bback {
50
+ background: rgba(0,0,0,0.5);
51
+ }
52
+ #contents {
53
+ position:fixed;
54
+ top:0;
55
+ right:0;
56
+ bottom:0;
57
+ left:0;
58
+ min-height:100vh;
59
+ overflow-y:scroll;
60
+ width:100%;
61
+ }
62
+ #top {
63
+ background: #000;
64
+ width: 100%;
65
+ height: 100vh;
66
+ overflow: hidden;
67
+ position: relative;
68
+ }
69
+ main {
70
+ padding: 0.5rem;
71
+ min-height: calc(100vh - 300px);/*フッター固定用の指定です*/
72
+ }
73
+ ```
32
74
  ------------------------
33
75
  jQueryのバージョンは2.24です。
34
76
  どなたか解決方法を教えてください。