質問編集履歴

1

実際のコードを追加しました。

2021/05/23 04:40

投稿

otakedesu
otakedesu

スコア2

test CHANGED
File without changes
test CHANGED
@@ -53,3 +53,447 @@
53
53
 
54
54
 
55
55
  こちら2点の実装方法をご教授願います。
56
+
57
+
58
+
59
+ # 追加情報(該当のコード)
60
+
61
+ ```HTML
62
+
63
+ <header class="header">
64
+
65
+ <!-- hamburger -->
66
+
67
+ <button
68
+
69
+ type="button"
70
+
71
+ id="js-hamburger"
72
+
73
+ class="header__hamburfer hamburger"
74
+
75
+ aria-expanded="false"
76
+
77
+ >
78
+
79
+ <span class="hamburger__line"> </span>
80
+
81
+ </button>
82
+
83
+ <!-- drawer-background -->
84
+
85
+ <div
86
+
87
+ class="header__drawer-back drawer-background"
88
+
89
+ id="js-drawer-background"
90
+
91
+ ></div>
92
+
93
+ <!-- sp-menu -->
94
+
95
+ <div class="header__drawer drawer">
96
+
97
+ <div class="drawer__logo-box">
98
+
99
+ <a href="front-page.html" class="drawer__logo-link">
100
+
101
+ <img
102
+
103
+ src="/assets/images/common/logo.png"
104
+
105
+ alt="ロゴの写真"
106
+
107
+ class="drawer__logo"
108
+
109
+ />
110
+
111
+ </a>
112
+
113
+ </div>
114
+
115
+ <nav class="drawer__nav sp-menu" id="js-global-menu">
116
+
117
+ <ul class="sp-menu__list">
118
+
119
+ <li class="sp-menu__item">
120
+
121
+ <a href="front-page.html" class="sp-menu__link">ホーム</a>
122
+
123
+ </li>
124
+
125
+ <li class="sp-menu__item">
126
+
127
+ <a href="archive-news.html" class="sp-menu__link">お知らせ</a>
128
+
129
+ </li>
130
+
131
+ <li class="sp-menu__item">
132
+
133
+ <a href="home.html" class="sp-menu__link">ブログ</a>
134
+
135
+ </li>
136
+
137
+ <li class="sp-menu__item">
138
+
139
+ <a href="page-price.html" class="sp-menu__link">コース・料金</a>
140
+
141
+ </li>
142
+
143
+ </ul>
144
+
145
+ </nav>
146
+
147
+ <div class="drawer__button-area">
148
+
149
+ <div class="drawer__button-box">
150
+
151
+ <a href="#" class="drawer__button drawer__button--orange">資料請求</a>
152
+
153
+ </div>
154
+
155
+ <div class="drawer__button-box">
156
+
157
+ <a href="#" class="drawer__button drawer__button--blue">お問い合わせ</a>
158
+
159
+ </div>
160
+
161
+ </div>
162
+
163
+ </div>
164
+
165
+ </header>
166
+
167
+ ```
168
+
169
+ ```SCSS
170
+
171
+ // ハンバーガー
172
+
173
+ .hamburger {
174
+
175
+ position: fixed;
176
+
177
+ top: 16px;
178
+
179
+ right: 25px;
180
+
181
+ z-index: 50;
182
+
183
+ width: 48px;
184
+
185
+ height: 48px;
186
+
187
+ border-radius: 50%;
188
+
189
+ border: 1px solid black;
190
+
191
+ box-shadow: 0 0 rem(15) transparent;
192
+
193
+ outline: none;
194
+
195
+ transition: all 0.3s ease-in-out;
196
+
197
+ -webkit-transition: all 0.3s ease-in-out;
198
+
199
+ display: none;
200
+
201
+ }
202
+
203
+ @media screen and (max-width: 1,000px) {
204
+
205
+ .hamburger {
206
+
207
+ display: block;
208
+
209
+ }
210
+
211
+ }
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ // ハンバーガーの線
220
+
221
+ .hamburger__line {
222
+
223
+ position: absolute;
224
+
225
+ top: 0;
226
+
227
+ right: 0;
228
+
229
+ bottom: 0;
230
+
231
+ left: 0;
232
+
233
+ margin: auto;
234
+
235
+ width: 18px;
236
+
237
+ height: 2px;
238
+
239
+ background: black;
240
+
241
+ transition: inherit;
242
+
243
+ -webkit-transition: inherit;
244
+
245
+ &::before,
246
+
247
+ &::after {
248
+
249
+ position: absolute;
250
+
251
+ display: block;
252
+
253
+ width: 100%;
254
+
255
+ height: 100%;
256
+
257
+ background-color: inherit;
258
+
259
+ content: "";
260
+
261
+ transition: inherit;
262
+
263
+ -webkit-transition: inherit;
264
+
265
+ }
266
+
267
+ &::before {
268
+
269
+ top: -5px;
270
+
271
+ }
272
+
273
+ &::after {
274
+
275
+ top: 5px;
276
+
277
+ }
278
+
279
+ }
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ // ドロワー時背景マスク
288
+
289
+ .drawer-background {
290
+
291
+ position: fixed;
292
+
293
+ z-index: $layer-floating;
294
+
295
+ width: 100vw;
296
+
297
+ top: 0;
298
+
299
+ right: 0;
300
+
301
+ bottom: 0;
302
+
303
+ overflow: hidden;
304
+
305
+ height: 100vh;
306
+
307
+ background: black;
308
+
309
+ color: white;
310
+
311
+ visibility: hidden;
312
+
313
+ opacity: 0;
314
+
315
+ display: none;
316
+
317
+ }
318
+
319
+ @media screen and (max-width: 1,000px) {
320
+
321
+ .drawer-background {
322
+
323
+ display: block;
324
+
325
+ }
326
+
327
+ }
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+ // spメニュー
336
+
337
+ .drawer {
338
+
339
+ position: fixed;
340
+
341
+ z-index: $layer-drawer;
342
+
343
+ width: 280px;
344
+
345
+ top: 0;
346
+
347
+ right: 0;
348
+
349
+ bottom: 0;
350
+
351
+ overflow: hidden;
352
+
353
+ height: 100vh;
354
+
355
+ background-color: white;
356
+
357
+ transform: translateX(280px);
358
+
359
+ transition: 0.3s;
360
+
361
+ display: none;
362
+
363
+ }
364
+
365
+ @media screen and (max-width: 1,000px) {
366
+
367
+ .drawer {
368
+
369
+ display: block;
370
+
371
+ }
372
+
373
+ }
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+ // aria-expandedがtrueになったら
382
+
383
+ .hamburger[aria-expanded="true"] .hamburger__line {
384
+
385
+ background-color: transparent;
386
+
387
+ &::before,
388
+
389
+ &::after {
390
+
391
+ top: 0;
392
+
393
+ background-color: black;
394
+
395
+ }
396
+
397
+ }
398
+
399
+ .hamburger[aria-expanded="true"] .hamburger__line::before {
400
+
401
+ transform: rotate(45deg);
402
+
403
+ -webkit-transform: rotate(45deg);
404
+
405
+ -ms-transform: rotate(45deg);
406
+
407
+ }
408
+
409
+ .hamburger[aria-expanded="true"] .hamburger__line::after {
410
+
411
+ transform: rotate(-45deg);
412
+
413
+ -webkit-transform: rotate(-45deg);
414
+
415
+ -ms-transform: rotate(-45deg);
416
+
417
+ }
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+ // jsでクラス追加
426
+
427
+ .is-drawerActive {
428
+
429
+ // 背景固定
430
+
431
+ height: 100%;
432
+
433
+ overflow: hidden;
434
+
435
+
436
+
437
+ .drawer {
438
+
439
+ transform: translateX(0px);
440
+
441
+ transition: 0.3s;
442
+
443
+ }
444
+
445
+ .drawer-background {
446
+
447
+ visibility: visible;
448
+
449
+ opacity: 0.8;
450
+
451
+ transition: 0.3s;
452
+
453
+ }
454
+
455
+ }
456
+
457
+ ```
458
+
459
+ ```JavaScript
460
+
461
+ $(function () {
462
+
463
+ $('#js-hamburger').click(function () {
464
+
465
+ $('body').toggleClass('is-drawerActive');
466
+
467
+
468
+
469
+ if ($(this).attr('aria-expanded') == 'false') {
470
+
471
+ $(this).attr('aria-expanded', 'true');
472
+
473
+ $('#js-global-menu').attr('area-hidden', 'false');
474
+
475
+ } else {
476
+
477
+ $(this).attr('aria-expanded', 'false');
478
+
479
+ $('#js-global-menu').attr('area-hidden', 'true');
480
+
481
+ }
482
+
483
+ });
484
+
485
+
486
+
487
+ $('#js-drawer-background').click(function () {
488
+
489
+ $('body').removeClass('is-drawerActive');
490
+
491
+ $('#js-hamburger').attr('aria-expanded', 'false');
492
+
493
+ $('#js-global-menu').attr('area-hidden', 'true');
494
+
495
+ });
496
+
497
+ });
498
+
499
+ ```