質問編集履歴
2
デモ用に問題点が分かりやすく修正しました。ご確認おねがいいたします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,24 +1,128 @@
|
|
1
1
|
ハンバーガーメニューをクリックすると、ページのトップまで勝手に戻ってしまいます。クリックした位置のままメニューを表示させるのは、どうすればいいのでしょうか?
|
2
2
|
|
3
|
+
画面幅をスマホサイズにすると、下記のコードでハンバーガーメニューが表示されます。
|
4
|
+
|
3
5
|
|
4
6
|
|
5
7
|
【ハンバーガーメニューのHTML】
|
6
8
|
|
9
|
+
``` <div class="header">
|
10
|
+
|
11
|
+
<a href="/top/index.html" class="header-top">PON DESIGN</a>
|
12
|
+
|
13
|
+
<!-- ハンバーガーメニュー -->
|
14
|
+
|
7
|
-
|
15
|
+
<input id="menu" type="checkbox">
|
8
|
-
|
16
|
+
|
9
|
-
<label for="menu" class="open menu-btn"><div class="line"></div><div class="line"></div><div class="line"></div></label>
|
17
|
+
<label for="menu" class="open menu-btn"><div class="line"></div><div class="line"></div><div class="line"></div></label>
|
10
|
-
|
18
|
+
|
11
|
-
<label for="menu" class="back"></label>
|
19
|
+
<label for="menu" class="back menu-btn"></label>
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
|
21
|
+
|
22
|
+
|
15
|
-
<aside class="nav-menu">
|
23
|
+
<aside class="nav-menu">
|
16
|
-
|
24
|
+
|
17
|
-
<label for="menu" class="close menu-btn">×</label>
|
25
|
+
<label for="menu" class="close menu-btn">×</label>
|
18
|
-
|
26
|
+
|
19
|
-
<!--
|
27
|
+
<!-- メニュー(SP) -->
|
28
|
+
|
20
|
-
|
29
|
+
<nav class="drawer-content">
|
30
|
+
|
31
|
+
<ul class="drawer-list">
|
32
|
+
|
33
|
+
<li class="drawer-item">
|
34
|
+
|
35
|
+
<a class="link-item" href="/news/news.html">NEWS</a>
|
36
|
+
|
37
|
+
</li>
|
38
|
+
|
39
|
+
<li class="drawer-item">
|
40
|
+
|
41
|
+
<a class="link-item" href="/service/service.html">SERVICE</a>
|
42
|
+
|
43
|
+
</li>
|
44
|
+
|
45
|
+
<li class="drawer-item">
|
46
|
+
|
47
|
+
<a class="link-item" href="/works/works.html">WORKS</a>
|
48
|
+
|
49
|
+
</li>
|
50
|
+
|
51
|
+
<li class="drawer-item">
|
52
|
+
|
53
|
+
<a class="link-item" href="/company/company.html">COMPANY</a>
|
54
|
+
|
55
|
+
</li>
|
56
|
+
|
57
|
+
<li class="drawer-item">
|
58
|
+
|
59
|
+
<a class="link-item" href="/recruit/recruit.html">RECRUIT</a>
|
60
|
+
|
61
|
+
</li>
|
62
|
+
|
63
|
+
<li class="drawer-item">
|
64
|
+
|
65
|
+
<a class="link-item" href="/contact/contact.html">CONTACT</a>
|
66
|
+
|
67
|
+
</li>
|
68
|
+
|
69
|
+
</ul>
|
70
|
+
|
71
|
+
</nav>
|
72
|
+
|
21
|
-
</aside>
|
73
|
+
</aside>
|
74
|
+
|
75
|
+
<!-- メニュー(PC) -->
|
76
|
+
|
77
|
+
<header class="header-nav">
|
78
|
+
|
79
|
+
<nav>
|
80
|
+
|
81
|
+
<ul class="nav-list">
|
82
|
+
|
83
|
+
<li class="nav-item">
|
84
|
+
|
85
|
+
<a href="/news/news.html">NEWS</a>
|
86
|
+
|
87
|
+
</li>
|
88
|
+
|
89
|
+
<li class="nav-item">
|
90
|
+
|
91
|
+
<a href="/service/service.html">SERVICE</a>
|
92
|
+
|
93
|
+
</li>
|
94
|
+
|
95
|
+
<li class="nav-item">
|
96
|
+
|
97
|
+
<a href="/works/works.html">WORKS</a>
|
98
|
+
|
99
|
+
</li>
|
100
|
+
|
101
|
+
<li class="nav-item">
|
102
|
+
|
103
|
+
<a href="/company/company.html">COMPANY</a>
|
104
|
+
|
105
|
+
</li>
|
106
|
+
|
107
|
+
<li class="nav-item">
|
108
|
+
|
109
|
+
<a href="/recruit/recruit.html">RECRUIT</a>
|
110
|
+
|
111
|
+
</li>
|
112
|
+
|
113
|
+
<li class="nav-item">
|
114
|
+
|
115
|
+
<a href="/contact/contact.html">CONTACT</a>
|
116
|
+
|
117
|
+
</li>
|
118
|
+
|
119
|
+
</ul>
|
120
|
+
|
121
|
+
</nav>
|
122
|
+
|
123
|
+
</header>
|
124
|
+
|
125
|
+
</aside>
|
22
126
|
|
23
127
|
|
24
128
|
|
@@ -28,125 +132,281 @@
|
|
28
132
|
|
29
133
|
```/* ハンバーガーメニュー */
|
30
134
|
|
31
|
-
.
|
135
|
+
.header-nav {
|
32
136
|
|
33
137
|
display: none;
|
34
138
|
|
35
|
-
}
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
36
|
-
|
143
|
+
.header {
|
144
|
+
|
37
|
-
|
145
|
+
background-image: url("/images/SP-TOP/hero@2x.jpg");
|
146
|
+
|
38
|
-
|
147
|
+
background-size: cover;
|
148
|
+
|
149
|
+
height: 812px;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
.drawer-list {
|
156
|
+
|
157
|
+
display: none;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
.header .header-top {
|
162
|
+
|
163
|
+
color: white;
|
164
|
+
|
165
|
+
display: block;
|
166
|
+
|
167
|
+
width: 130px;
|
168
|
+
|
169
|
+
font-size: 18px;
|
170
|
+
|
171
|
+
font-weight: bold;
|
172
|
+
|
173
|
+
padding: 20px 0 0 15px;
|
174
|
+
|
175
|
+
text-decoration: none;
|
176
|
+
|
177
|
+
position: absolute;
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
.header .header-top:hover {
|
184
|
+
|
185
|
+
opacity: 0.8;
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
.header .header-active {
|
192
|
+
|
193
|
+
display: none;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
.header .header-img-active {
|
200
|
+
|
201
|
+
display: none;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
/* ハンバーガーメニュー */
|
208
|
+
|
209
|
+
.open, .close {
|
210
|
+
|
211
|
+
display: none;
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
39
|
-
/* 三本線 */
|
217
|
+
/* 三本線 */
|
40
|
-
|
218
|
+
|
41
|
-
.line {
|
219
|
+
.line {
|
42
|
-
|
220
|
+
|
43
|
-
width:
|
221
|
+
width: 30px;
|
44
222
|
|
45
223
|
height: 2px;
|
46
224
|
|
47
|
-
background-color:
|
225
|
+
background-color: white;
|
48
|
-
|
226
|
+
|
49
|
-
margin:
|
227
|
+
margin: 6px;
|
50
|
-
|
228
|
+
|
51
|
-
}
|
229
|
+
}
|
52
|
-
|
53
|
-
|
54
|
-
|
230
|
+
|
231
|
+
|
232
|
+
|
55
|
-
/* 左に隠す */
|
233
|
+
/* 左に隠す */
|
56
|
-
|
234
|
+
|
57
|
-
input[type="checkbox"] {
|
235
|
+
input[type="checkbox"] {
|
58
236
|
|
59
237
|
position: absolute;
|
60
238
|
|
61
239
|
left: -50vw;
|
62
240
|
|
63
|
-
}
|
241
|
+
}
|
64
|
-
|
65
|
-
|
66
|
-
|
242
|
+
|
243
|
+
|
244
|
+
|
67
|
-
@media(max-width: 10
|
245
|
+
@media (max-width: 1150px) {
|
68
246
|
|
69
247
|
.open, .close {
|
70
248
|
|
71
|
-
|
249
|
+
display: block;
|
72
|
-
|
250
|
+
|
73
|
-
}
|
251
|
+
}
|
74
|
-
|
75
|
-
|
252
|
+
|
253
|
+
|
76
254
|
|
77
255
|
.close {/* ×のデザイン */
|
78
256
|
|
79
|
-
|
257
|
+
font-size: 40px;
|
258
|
+
|
80
|
-
|
259
|
+
color: white;
|
260
|
+
|
261
|
+
position: absolute;
|
262
|
+
|
263
|
+
right: 30px;
|
264
|
+
|
265
|
+
top: 10px;
|
266
|
+
|
81
|
-
}
|
267
|
+
}
|
82
|
-
|
83
|
-
|
268
|
+
|
269
|
+
|
84
270
|
|
85
271
|
.open {
|
86
272
|
|
87
|
-
|
273
|
+
position: absolute;
|
274
|
+
|
88
|
-
|
275
|
+
right: 30px;
|
276
|
+
|
277
|
+
top: 15px;
|
278
|
+
|
279
|
+
position: fixed;
|
280
|
+
|
89
|
-
}
|
281
|
+
}
|
282
|
+
|
90
|
-
|
283
|
+
.drawer-list {
|
284
|
+
|
91
|
-
|
285
|
+
display: block;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
92
290
|
|
93
291
|
/* コンテンツを隠す */
|
94
292
|
|
95
|
-
a
|
293
|
+
.nav-menu {
|
96
|
-
|
294
|
+
|
97
|
-
|
295
|
+
position: absolute;
|
98
|
-
|
296
|
+
|
99
|
-
|
297
|
+
right: -30%;
|
100
|
-
|
298
|
+
|
101
|
-
|
299
|
+
height: 812px;
|
102
|
-
|
300
|
+
|
103
|
-
|
301
|
+
transition: all 0.2s;
|
302
|
+
|
104
|
-
|
303
|
+
background: url(/images/SP-TOP/backimg-menu@2x.png);
|
304
|
+
|
105
|
-
|
305
|
+
z-index: 1000;
|
306
|
+
|
106
|
-
|
307
|
+
width: 30%;
|
308
|
+
|
107
|
-
}
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
108
|
-
|
313
|
+
.link-item {
|
314
|
+
|
109
|
-
|
315
|
+
color: white;
|
316
|
+
|
317
|
+
text-decoration: none;
|
318
|
+
|
319
|
+
margin-top: 100px;
|
320
|
+
|
321
|
+
margin-bottom: -50px;
|
322
|
+
|
323
|
+
display: block;
|
324
|
+
|
325
|
+
text-align: center;
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
.link-news {
|
332
|
+
|
333
|
+
margin-top: 100px;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
.link-item:hover {
|
340
|
+
|
341
|
+
text-decoration: underline;
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
110
346
|
|
111
347
|
input[type="checkbox"]:checked ~ .nav-menu {
|
112
348
|
|
113
|
-
|
349
|
+
right: 0;
|
114
|
-
|
350
|
+
|
115
|
-
}
|
351
|
+
}
|
116
|
-
|
117
|
-
|
352
|
+
|
353
|
+
|
118
354
|
|
119
355
|
input[type="checkbox"]:checked ~ .back {
|
120
356
|
|
121
|
-
|
357
|
+
position: absolute;
|
122
|
-
|
358
|
+
|
123
|
-
|
359
|
+
width: 100%;
|
124
|
-
|
360
|
+
|
125
|
-
|
361
|
+
height: 100%;
|
126
|
-
|
362
|
+
|
127
|
-
|
363
|
+
background: rgb(0, 0, 0, 0.8);
|
364
|
+
|
128
|
-
|
365
|
+
z-index: 100;
|
366
|
+
|
129
|
-
}
|
367
|
+
}
|
130
|
-
|
131
|
-
|
132
|
-
|
368
|
+
|
369
|
+
|
370
|
+
|
133
|
-
}
|
371
|
+
}
|
134
|
-
|
372
|
+
|
373
|
+
|
374
|
+
|
135
|
-
body.hidden{
|
375
|
+
body.hidden{
|
136
376
|
|
137
377
|
overflow: hidden;
|
138
378
|
|
379
|
+
background: red;
|
380
|
+
|
139
|
-
}
|
381
|
+
}
|
382
|
+
|
383
|
+
|
384
|
+
|
140
|
-
|
385
|
+
body {
|
386
|
+
|
141
|
-
|
387
|
+
background: red;
|
388
|
+
|
389
|
+
height: 5000px;
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
142
394
|
|
143
395
|
```
|
144
396
|
|
145
397
|
【ハンバーガーメニューのJS(hiddenクラスのつけ外しで、メニュー表示時bodyをスクロールさせないように固定している】
|
146
398
|
|
399
|
+
```
|
400
|
+
|
147
|
-
|
401
|
+
$(function() {
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
148
|
-
|
407
|
+
$(function() {
|
408
|
+
|
149
|
-
$('.menu-btn').click(function() {
|
409
|
+
$('.menu-btn').click(function() {
|
150
410
|
|
151
411
|
if($('body').hasClass('hidden')) {
|
152
412
|
|
@@ -160,6 +420,12 @@
|
|
160
420
|
|
161
421
|
});
|
162
422
|
|
423
|
+
});
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
});
|
428
|
+
|
163
429
|
|
164
430
|
|
165
431
|
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
```<input id="menu" type="checkbox">
|
8
8
|
|
9
|
-
<label for="menu" class="open"><div class="line"></div><div class="line"></div><div class="line"></div></label>
|
9
|
+
<label for="menu" class="open menu-btn"><div class="line"></div><div class="line"></div><div class="line"></div></label>
|
10
10
|
|
11
11
|
<label for="menu" class="back"></label>
|
12
12
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
<aside class="nav-menu">
|
16
16
|
|
17
|
-
<label for="menu" class="close">×</label>
|
17
|
+
<label for="menu" class="close menu-btn">×</label>
|
18
18
|
|
19
19
|
<!-- コンテンツ -->
|
20
20
|
|
@@ -160,7 +160,9 @@
|
|
160
160
|
|
161
161
|
});
|
162
162
|
|
163
|
-
|
163
|
+
|
164
|
+
|
165
|
+
|
164
166
|
|
165
167
|
|
166
168
|
|