回答編集履歴

1

追記

2021/12/29 12:23

投稿

umau
umau

スコア805

test CHANGED
@@ -21,3 +21,511 @@
21
21
  ...
22
22
 
23
23
  ```
24
+
25
+
26
+
27
+ ---
28
+
29
+ (追記)こちらで動いたソース一式貼っておきます。(cssは全く触ってません)
30
+
31
+ ```html
32
+
33
+ <!DOCTYPE html>
34
+
35
+ <html>
36
+
37
+ <head>
38
+
39
+ <title></title>
40
+
41
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
42
+
43
+ <link href="./hoge.css" rel="stylesheet">
44
+
45
+ <script src="./hoge.js"></script>
46
+
47
+
48
+
49
+ </head>
50
+
51
+
52
+
53
+ <body>
54
+
55
+ <header class="header">
56
+
57
+ <div class="header-inner">
58
+
59
+ <div class="header-left">
60
+
61
+ <h1>aaa</h1>
62
+
63
+ <!-- <h1 class="logo"><a href="#"><img alt="" class="header-logo" src="./asserts/img/top-header-logo.png"></a></h1> -->
64
+
65
+ <nav class="nav drawer-nav">
66
+
67
+ <ul class="header-list">
68
+
69
+ <li class="header-item">
70
+
71
+ <a href="./Room/room.html">お部屋</a>
72
+
73
+ </li><!-- /.header-item -->
74
+
75
+ <li class="header-item">
76
+
77
+ <a href="./Menu/menu.html">お料理</a>
78
+
79
+ </li><!-- /.header-item -->
80
+
81
+ <li class="header-item">
82
+
83
+ <a href="./Onsen/onsen.html">温泉</a>
84
+
85
+ </li><!-- /.header-item -->
86
+
87
+ </ul><!-- /.header-list -->
88
+
89
+ </nav><!-- /.nav -->
90
+
91
+ </div>
92
+
93
+ <div class="header-right">
94
+
95
+ <div class="header-link" id="js-modal">
96
+
97
+ <a class="calender-link js-modal-open" href="#"><!-- <img src="./img/calender.png" alt="カレンダー"> -->
98
+
99
+ 宿泊予約</a>
100
+
101
+ </div><!-- /.header-link -->
102
+
103
+ <button aria-controls="js-glabal-menu" aria-expanded="false" class="humburger" id="js-humburger" type="button"><span class="line"></span><span class="line"></span><span class="line"></span></button>
104
+
105
+ </div><!-- /.header-right -->
106
+
107
+ </div><!-- /.header-inner -->
108
+
109
+ </header><!-- /.header -->
110
+
111
+ <div class="overlay"></div><!-- /.overlay -->
112
+
113
+ </body>
114
+
115
+ </html>
116
+
117
+ ```
118
+
119
+ ```javascript
120
+
121
+ $(function(){
122
+
123
+
124
+
125
+ $(".humburger").on('click', function(){
126
+
127
+
128
+
129
+ if($(this).hasClass('_active')){
130
+
131
+
132
+
133
+ $(this).removeClass('_active');
134
+
135
+ $(".line").removeClass('_open');
136
+
137
+ $("nav").removeClass("nav-open");
138
+
139
+ // $(".drawer-nav").removeClass('_active');
140
+
141
+ $('.overlay').removeClass('_open');
142
+
143
+ $('html').removeClass('scroll-prevent') // 追記
144
+
145
+
146
+
147
+ } else {
148
+
149
+ $(this).addClass('_active');
150
+
151
+
152
+
153
+ $('.line').addClass('_open');
154
+
155
+ $("nav").addClass("nav-open");
156
+
157
+
158
+
159
+ $('.overlay').addClass('_open');
160
+
161
+ $('html').toggleClass('scroll-prevent') // 背景を固定
162
+
163
+ }
164
+
165
+ });
166
+
167
+
168
+
169
+ $('.overlay').on('click',function(){
170
+
171
+
172
+
173
+ if($(this).hasClass('_open')){
174
+
175
+
176
+
177
+ $(this).removeClass('_open');
178
+
179
+ $('.humburger').removeClass('_active');
180
+
181
+ $('.line').removeClass('_open');
182
+
183
+
184
+
185
+ $("nav").removeClass('nav-open');
186
+
187
+ $('html').removeClass('scroll-prevent') // 追記
188
+
189
+ // $('.drawer-nav').removeClass('_active');
190
+
191
+
192
+
193
+ }
194
+
195
+ });
196
+
197
+
198
+
199
+ $('.humburger_active').on('click',function(){
200
+
201
+
202
+
203
+ if($(this).hasClass('_active')){
204
+
205
+
206
+
207
+ $(this).removeClass('_active');
208
+
209
+ $('.line').removeClass('_open');
210
+
211
+
212
+
213
+ $("nav").removeClass('nav-open');
214
+
215
+ $('.overlay').removeClass('_open');
216
+
217
+ $('html').removeClass('scroll-prevent') // 追記
218
+
219
+ // $('.drawer-nav').removeClass('_active');
220
+
221
+ }
222
+
223
+ });
224
+
225
+
226
+
227
+
228
+
229
+ });
230
+
231
+ ```
232
+
233
+
234
+
235
+ ```css
236
+
237
+ .header-left .nav {
238
+
239
+ display: -webkit-box;
240
+
241
+ display: -webkit-flex;
242
+
243
+ display: -ms-flexbox;
244
+
245
+ display: flex;
246
+
247
+ -webkit-box-pack: justify;
248
+
249
+ -webkit-justify-content: space-between;
250
+
251
+ -ms-flex-pack: justify;
252
+
253
+ justify-content: space-between;
254
+
255
+ -webkit-box-align: center;
256
+
257
+ -webkit-align-items: center;
258
+
259
+ -ms-flex-align: center;
260
+
261
+ align-items: center;
262
+
263
+ margin-left: 120px;
264
+
265
+ }
266
+
267
+
268
+
269
+ .header-left .nav-open {
270
+
271
+ -webkit-transform: translateZ(0);
272
+
273
+ transform: translateZ(0);
274
+
275
+ }
276
+
277
+
278
+
279
+ @media screen and (min-width: 600px) and (max-width: 1179px) {
280
+
281
+ .header-left .nav {
282
+
283
+ top: 80px;
284
+
285
+ position: fixed;
286
+
287
+ top: 150px;
288
+
289
+ right: 0;
290
+
291
+ z-index: 10;
292
+
293
+ overflow: hidden;
294
+
295
+ width: 16.25rem;
296
+
297
+ background-color: #000;
298
+
299
+ width: 50%;
300
+
301
+ height: 60vh;
302
+
303
+ -webkit-transform: translate(550px);
304
+
305
+ transform: translate(550px);
306
+
307
+ -webkit-transition: .5s;
308
+
309
+ transition: .5s;
310
+
311
+ }
312
+
313
+ .header-left .nav-open {
314
+
315
+ -webkit-transform: translateZ(0);
316
+
317
+ transform: translateZ(0);
318
+
319
+ }
320
+
321
+ }
322
+
323
+
324
+
325
+ @media screen and (max-width: 599px) {
326
+
327
+ .header-left .nav {
328
+
329
+ top: 60px;
330
+
331
+ position: fixed;
332
+
333
+ z-index: 2;
334
+
335
+ overflow: hidden;
336
+
337
+ width: 16.25rem;
338
+
339
+ background-color: rgba(0, 0, 0, 0.9);
340
+
341
+ width: 75%;
342
+
343
+ -webkit-transform: translate(550px);
344
+
345
+ transform: translate(550px);
346
+
347
+ -webkit-transition: margin-left .5s;
348
+
349
+ transition: margin-left .5s;
350
+
351
+ }
352
+
353
+ .header-left .nav-open {
354
+
355
+ -webkit-transform: translateZ(0);
356
+
357
+ transform: translateZ(0);
358
+
359
+ }
360
+
361
+ }
362
+
363
+
364
+
365
+ .header-left .nav .header-list {
366
+
367
+ display: -webkit-box;
368
+
369
+ display: -webkit-flex;
370
+
371
+ display: -ms-flexbox;
372
+
373
+ display: flex;
374
+
375
+ -webkit-box-align: center;
376
+
377
+ -webkit-align-items: center;
378
+
379
+ -ms-flex-align: center;
380
+
381
+ align-items: center;
382
+
383
+ padding-top: 20px;
384
+
385
+ padding-bottom: 20px;
386
+
387
+ }
388
+
389
+
390
+
391
+ @media screen and (min-width: 600px) and (max-width: 1179px) {
392
+
393
+ .header-left .nav .header-list {
394
+
395
+ display: -webkit-box;
396
+
397
+ display: -webkit-flex;
398
+
399
+ display: -ms-flexbox;
400
+
401
+ display: flex;
402
+
403
+ -webkit-box-orient: vertical;
404
+
405
+ -webkit-box-direction: normal;
406
+
407
+ -webkit-flex-direction: column;
408
+
409
+ -ms-flex-direction: column;
410
+
411
+ flex-direction: column;
412
+
413
+ margin: 100px;
414
+
415
+ text-align: center;
416
+
417
+ padding-left: 40px;
418
+
419
+ }
420
+
421
+ }
422
+
423
+
424
+
425
+ @media screen and (max-width: 599px) {
426
+
427
+ .header-left .nav .header-list {
428
+
429
+ margin-right: 30px;
430
+
431
+ }
432
+
433
+ }
434
+
435
+
436
+
437
+ .header-left .nav .header-list .header-item {
438
+
439
+ color: #fff;
440
+
441
+ }
442
+
443
+
444
+
445
+ @media screen and (min-width: 600px) and (max-width: 1179px) {
446
+
447
+ .header-left .nav .header-list .header-item {
448
+
449
+ padding-left: 20px;
450
+
451
+ }
452
+
453
+ }
454
+
455
+
456
+
457
+ @media screen and (max-width: 599px) {
458
+
459
+ .header-left .nav .header-list .header-item {
460
+
461
+ padding: 0px;
462
+
463
+ font-size: 2rem;
464
+
465
+ }
466
+
467
+ }
468
+
469
+
470
+
471
+ .header-left .nav .header-list .header-item + .header-item {
472
+
473
+ padding-left: 30px;
474
+
475
+ }
476
+
477
+
478
+
479
+ @media screen and (min-width: 600px) and (max-width: 1179px) {
480
+
481
+ .header-left .nav .header-list .header-item + .header-item {
482
+
483
+ padding-left: 0px;
484
+
485
+ }
486
+
487
+ }
488
+
489
+
490
+
491
+ @media screen and (max-width: 599px) {
492
+
493
+ .header-left .nav .header-list .header-item + .header-item {
494
+
495
+ padding-left: 0px;
496
+
497
+ }
498
+
499
+ }
500
+
501
+
502
+
503
+ .header-left .nav .header-list .header-item > a {
504
+
505
+ color: #fff;
506
+
507
+ display: inline-block;
508
+
509
+ -webkit-transition: .3s;
510
+
511
+ transition: .3s;
512
+
513
+ /* 0.3秒で拡大までの時間 */
514
+
515
+ }
516
+
517
+
518
+
519
+ @media screen and (min-width: 600px) and (max-width: 1179px) {
520
+
521
+ .header-left .nav .header-list .header-item > a {
522
+
523
+ padding-bottom: 65px;
524
+
525
+ font-size: 2.4rem;
526
+
527
+ }
528
+
529
+ }
530
+
531
+ ```