質問編集履歴

1

コードへ追記

2016/08/19 08:10

投稿

misonya
misonya

スコア25

test CHANGED
File without changes
test CHANGED
@@ -10,21 +10,161 @@
10
10
 
11
11
  ```JavaScript
12
12
 
13
- if (window.matchMedia('screen and (min-width:1200px)').matches) {
13
+ if(window.matchMedia('(min-width:1200px)').matches) {
14
+
15
+ //画面幅が992px以上の場合のみ有効。ページ更新時のWindow幅で判断。
14
16
 
15
17
  $(function() {
16
18
 
19
+ $('#room-search').hide();
20
+
21
+ var gnavi = $('#header-mid');
22
+
23
+ var gnaviTop = gnavi.offset().top;
24
+
25
+ var gnaviHeight = gnavi.height();
26
+
27
+ var bottom = $('#header-bottom');
28
+
29
+ var bottomTop = bottom.offset().top;
30
+
31
+ var bottomHeight = bottom.height();
32
+
33
+ bottom.css('top', -bottomHeight+'px');
34
+
35
+ $(window).scroll(function () {
36
+
37
+ //TOPから460pxスクロールしたときにroom-searchをほわっと出力。460px未満で隠す。
38
+
39
+ if($(this).scrollTop() <= 460 && !$('#room-search').is(':hidden')){
40
+
41
+ $('#room-search').hide();
42
+
43
+ }else if($(this).scrollTop() > 460 && $('#room-search').is(':hidden')){
44
+
45
+ $('#room-search').fadeIn("slow");
46
+
47
+ }
48
+
49
+ if(($(this).scrollTop() - gnaviTop) < 0){
50
+
51
+ //header-midがウィンドウ上部から離れたときの動作をしたときに適応
52
+
53
+ gnavi.height(gnaviHeight);
54
+
55
+ $('#global-navi li a').css({'padding' : '25px 35px'});
56
+
57
+ gnavi.css({position:"static", top: "auto"});
58
+
59
+ bottom.css({position:"static", top: "auto"});
60
+
61
+ bottom.removeClass('header-shadow');
62
+
63
+ }else if(($(this).scrollTop() - gnaviTop) < 55){
64
+
17
- //画面幅1200px以とき
65
+ //header-midウィンドウ部に触れたときの動作
66
+
67
+ gnavi.height((gnaviTop+gnaviHeight+4) - $(this).scrollTop());
68
+
69
+ gnavi.css({position:"fixed", top: 0});
70
+
71
+ bottom.css({position:"fixed", top: gnavi.height()});
72
+
73
+ bottom.removeClass('header-shadow');
74
+
75
+ $('#global-navi li a').css({'padding' : ((gnavi.height() -20)/2)+'px 35px'});
76
+
77
+ }else{
78
+
79
+ //ヘッダーに固定されたときheader-midの高さ30px確保し、ナビメニューの余白を上下5px左右20px保持
80
+
81
+ gnavi.height(30);
82
+
83
+ $('#global-navi li a').css({'padding' : '5px 35px'});
84
+
85
+ gnavi.css({position:"fixed", top: 0});
86
+
87
+ bottom.css({position:"fixed", top: gnavi.height()});
88
+
89
+ bottom.addClass('header-shadow');
90
+
91
+ }
18
92
 
19
93
  });
20
94
 
21
95
  });
22
96
 
23
- }else if (window.matchMedia('screen and (min-width:991px) and (max-width: 1200px)').matches) {
97
+ }else if (window.matchMedia('(min-width:991px) and (max-width: 1200px)').matches) {
24
98
 
25
99
  $(function() {
26
100
 
27
- //画面幅が991px以上1200px以下のとき
101
+ $('#room-search').hide();
102
+
103
+ var gnavi = $('#header-mid');
104
+
105
+ var gnaviTop = gnavi.offset().top;
106
+
107
+ var gnaviHeight = gnavi.height();
108
+
109
+ var bottom = $('#header-bottom');
110
+
111
+ var bottomTop = bottom.offset().top;
112
+
113
+ var bottomHeight = bottom.height();
114
+
115
+ bottom.css('top', -bottomHeight+'px');
116
+
117
+ $(window).scroll(function () {
118
+
119
+ if($(this).scrollTop() <= 460 && !$('#room-search').is(':hidden')){
120
+
121
+ $('#room-search').hide();
122
+
123
+ }else if($(this).scrollTop() > 460 && $('#room-search').is(':hidden')){
124
+
125
+ $('#room-search').fadeIn("slow");
126
+
127
+ }
128
+
129
+ if(($(this).scrollTop() - gnaviTop) < 0){
130
+
131
+ gnavi.height(gnaviHeight);
132
+
133
+ $('#global-navi li a').css({'padding' : '30px 20px'});
134
+
135
+ gnavi.css({position:"static", top: "auto"});
136
+
137
+ bottom.css({position:"static", top: "auto"});
138
+
139
+ bottom.removeClass('header-shadow');
140
+
141
+ }else if(($(this).scrollTop() - gnaviTop) < 55){
142
+
143
+ gnavi.height((gnaviTop+gnaviHeight+4) - $(this).scrollTop());
144
+
145
+ gnavi.css({position:"fixed", top: 0});
146
+
147
+ bottom.css({position:"fixed", top: gnavi.height()});
148
+
149
+ bottom.removeClass('header-shadow');
150
+
151
+ $('#global-navi li a').css({'padding' : ((gnavi.height() -20)/2)+'px 20px'});
152
+
153
+ }else{
154
+
155
+ gnavi.height(30);
156
+
157
+ $('#global-navi li a').css({'padding' : '5px 20px'});
158
+
159
+ gnavi.css({position:"fixed", top: 0});
160
+
161
+ bottom.css({position:"fixed", top: gnavi.height()});
162
+
163
+ bottom.addClass('header-shadow');
164
+
165
+ }
166
+
167
+ });
28
168
 
29
169
  });
30
170
 
@@ -32,7 +172,63 @@
32
172
 
33
173
  $(function() {
34
174
 
35
- //どれにも当てはまらなかったときの処理
175
+ $('#room-search').hide();
176
+
177
+ var gnavi = $('#header-mid');
178
+
179
+ var gnaviTop = gnavi.offset().top;
180
+
181
+ var gnaviHeight = gnavi.height();
182
+
183
+ var bottom = $('#header-bottom');
184
+
185
+ var bottomTop = bottom.offset().top;
186
+
187
+ var bottomHeight = bottom.height();
188
+
189
+ bottom.css('top', -bottomHeight+'px');
190
+
191
+ $(window).scroll(function () {
192
+
193
+ if(($(this).scrollTop() - gnaviTop) < 0){
194
+
195
+ gnavi.height(gnaviHeight);
196
+
197
+ $('#global-navi li a').css({'padding' : '30px 20px'});
198
+
199
+ gnavi.css({position:"static", top: "auto"});
200
+
201
+ bottom.css({position:"static", top: "auto"});
202
+
203
+ bottom.removeClass('header-shadow');
204
+
205
+ }else if(($(this).scrollTop() - gnaviTop) < 55){
206
+
207
+ gnavi.height((gnaviTop+gnaviHeight) - $(this).scrollTop());
208
+
209
+ gnavi.css({position:"fixed", top: 0});
210
+
211
+ bottom.css({position:"fixed", top: gnavi.height()});
212
+
213
+ bottom.removeClass('header-shadow');
214
+
215
+ $('#global-navi li a').css({'padding' : ((gnavi.height() -20)/2)+'px 20px'});
216
+
217
+ }else{
218
+
219
+ gnavi.height(30);
220
+
221
+ $('#global-navi li a').css({'padding' : '5px 20px'});
222
+
223
+ gnavi.css({position:"fixed", top: 0});
224
+
225
+ bottom.css({position:"fixed", top: gnavi.height()});
226
+
227
+ bottom.addClass('header-shadow');
228
+
229
+ }
230
+
231
+ });
36
232
 
37
233
  });
38
234