質問編集履歴

2

コードミス修正

2019/07/09 14:39

投稿

c_y
c_y

スコア12

test CHANGED
File without changes
test CHANGED
@@ -38,422 +38,422 @@
38
38
 
39
39
  $(this).toggleClass('active'); //ハンバーガーメニュートリガーを[=]マークから[×]に変える
40
40
 
41
+ if ($(this).hasClass('active')) {
42
+
43
+     current_scrollY = $( window ).scrollTop();
44
+
45
+ $('.globalMenuSp').addClass('active'); //ハンバーガーメニューを表示させる
46
+
47
+ $( 'body' ).css( { //スクロール位置を保持した状態にする
48
+
49
+ position: 'fixed',
50
+
51
+ width: '100%',
52
+
53
+ top: -1 * current_scrollY
54
+
55
+ } );
56
+
57
+ } else {
58
+
59
+ $('.globalMenuSp').removeClass('active');
60
+
61
+ $( 'body' ).attr( { style: '' } ); //bodyに当てたcssを外す
62
+
63
+ $("html,body").scrollTop(current_scrollY); //スクロール位置を保持した状態にしたいがここでtopに戻ってしまう
64
+
65
+ }
66
+
67
+ });
68
+
69
+ });
70
+
71
+
72
+
73
+ ```
74
+
75
+
76
+
77
+ ```HTML
78
+
79
+ <body>
80
+
81
+ <header id="the-nav">
82
+
83
+ <section id="nav_n_top_log">
84
+
85
+ <div class="container-fluid">
86
+
87
+ <div class="row">
88
+
89
+ <div class="col-3">
90
+
91
+ <a href="#">
92
+
93
+ <img src="logo.svg" class="img-fluid">
94
+
95
+ </a>
96
+
97
+ </div>
98
+
99
+ <div class="col-9">
100
+
101
+ <div class="row">
102
+
103
+ <div class="col-4 ml-auto">
104
+
105
+ <a class="menu-trigger">
106
+
107
+ <span></span>
108
+
109
+ <span></span>
110
+
111
+ </a>
112
+
113
+ </div>
114
+
115
+ <div class="col-12 stick-under-line">
116
+
117
+ <span>uncomfortable</span>
118
+
119
+ </div>
120
+
121
+ </div>
122
+
123
+ </div>
124
+
125
+ </div>
126
+
127
+ </div>
128
+
129
+ </section>
130
+
131
+ </header>
132
+
133
+ <nav class="globalMenuSp">
134
+
135
+ <ul>
136
+
137
+ <li><a href="#">Menu1</a></li>
138
+
139
+ <li><a href="#">Menu2</a></li>
140
+
141
+ <li><a href="#">Menu3</a></li>
142
+
143
+ <li><a href="#">Menu4</a></li>
144
+
145
+ <li><a href="#">Menu5</a></li>
146
+
147
+ </ul>
148
+
149
+ </nav>
150
+
151
+
152
+
153
+ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
154
+
155
+ <script src="js/jquery-3.2.1.min.js"></script>
156
+
157
+
158
+
159
+ <!-- Include all compiled plugins (below), or include individual files as needed -->
160
+
161
+ <script src="js/popper.min.js"></script>
162
+
163
+ <script src="js/bootstrap-4.0.0.js"></script>
164
+
165
+ <!--vivus js-->
166
+
167
+ <!-- <script src="js/vivus.min.js"></script> -->
168
+
169
+ <!--slick js-->
170
+
171
+ <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
172
+
173
+ <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
174
+
175
+ <script type="text/javascript" src="slick/slick.min.js"></script>
176
+
177
+
178
+
179
+ <script>
180
+
181
+ $(function(){
182
+
183
+ var current_scrollY;
184
+
185
+ $('.menu-trigger').on('click', function() {
186
+
187
+ $(this).toggleClass('active');
188
+
41
189
  current_scrollY = $( window ).scrollTop();
42
190
 
43
191
  if ($(this).hasClass('active')) {
44
192
 
45
- $('.globalMenuSp').addClass('active'); //ハンバーガーメニューを表示させる
193
+ $('.globalMenuSp').addClass('active');
46
-
194
+
47
- $( 'body' ).css( { //スクロール位置を保持した状態にする
195
+ $( 'body' ).css( {
48
196
 
49
197
  position: 'fixed',
50
198
 
51
199
  width: '100%',
52
200
 
201
+ //top位置をその時点のスクロール量分だけ上にずらす
202
+
53
203
  top: -1 * current_scrollY
54
204
 
55
205
  } );
56
206
 
207
+ // return false;
208
+
57
209
  } else {
58
210
 
59
211
  $('.globalMenuSp').removeClass('active');
60
212
 
61
- $( 'body' ).attr( { style: '' } ); //bodyに当てたcssを外す
213
+ $( 'body' ).attr( { style: '' } );
62
-
214
+
63
- $("html,body").scrollTop(current_scrollY); //スクロール位置を保持した状態にしたいがここでtopに戻ってしまう
215
+ $("html,body").scrollTop(current_scrollY);
64
216
 
65
217
  }
66
218
 
219
+
220
+
67
221
  });
68
222
 
69
223
  });
70
224
 
71
225
 
72
226
 
227
+
228
+
229
+
230
+
231
+ new Vivus('unconfortable_logo', {type: 'scenario-sync',duration: 20, forceRender: false ,animTimingFunction:Vivus.EASE})
232
+
233
+ </script>
234
+
235
+ </body>
236
+
73
237
  ```
74
238
 
75
239
 
76
240
 
77
- ```HTML
78
-
79
- <body>
80
-
81
- <header id="the-nav">
82
-
83
- <section id="nav_n_top_log">
84
-
85
- <div class="container-fluid">
86
-
87
- <div class="row">
88
-
89
- <div class="col-3">
90
-
91
- <a href="#">
92
-
93
- <img src="logo.svg" class="img-fluid">
94
-
95
- </a>
96
-
97
- </div>
98
-
99
- <div class="col-9">
100
-
101
- <div class="row">
102
-
103
- <div class="col-4 ml-auto">
104
-
105
- <a class="menu-trigger">
106
-
107
- <span></span>
108
-
109
- <span></span>
110
-
111
- </a>
112
-
113
- </div>
114
-
115
- <div class="col-12 stick-under-line">
116
-
117
- <span>uncomfortable</span>
118
-
119
- </div>
120
-
121
- </div>
122
-
123
- </div>
124
-
125
- </div>
126
-
127
- </div>
128
-
129
- </section>
130
-
131
- </header>
132
-
133
- <nav class="globalMenuSp">
134
-
135
- <ul>
136
-
137
- <li><a href="#">Menu1</a></li>
138
-
139
- <li><a href="#">Menu2</a></li>
140
-
141
- <li><a href="#">Menu3</a></li>
142
-
143
- <li><a href="#">Menu4</a></li>
144
-
145
- <li><a href="#">Menu5</a></li>
146
-
147
- </ul>
148
-
149
- </nav>
150
-
151
-
152
-
153
- <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
154
-
155
- <script src="js/jquery-3.2.1.min.js"></script>
156
-
157
-
158
-
159
- <!-- Include all compiled plugins (below), or include individual files as needed -->
160
-
161
- <script src="js/popper.min.js"></script>
162
-
163
- <script src="js/bootstrap-4.0.0.js"></script>
164
-
165
- <!--vivus js-->
166
-
167
- <!-- <script src="js/vivus.min.js"></script> -->
168
-
169
- <!--slick js-->
170
-
171
- <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
172
-
173
- <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
174
-
175
- <script type="text/javascript" src="slick/slick.min.js"></script>
176
-
177
-
178
-
179
- <script>
180
-
181
- $(function(){
182
-
183
- var current_scrollY;
184
-
185
- $('.menu-trigger').on('click', function() {
186
-
187
- $(this).toggleClass('active');
188
-
189
- current_scrollY = $( window ).scrollTop();
190
-
191
- if ($(this).hasClass('active')) {
192
-
193
- $('.globalMenuSp').addClass('active');
194
-
195
- $( 'body' ).css( {
196
-
197
- position: 'fixed',
198
-
199
- width: '100%',
200
-
201
- //top位置をその時点のスクロール量分だけ上にずらす
202
-
203
- top: -1 * current_scrollY
204
-
205
- } );
206
-
207
- // return false;
208
-
209
- } else {
210
-
211
- $('.globalMenuSp').removeClass('active');
212
-
213
- $( 'body' ).attr( { style: '' } );
214
-
215
- $("html,body").scrollTop(current_scrollY);
216
-
217
- }
218
-
219
-
220
-
221
- });
222
-
223
- });
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
- new Vivus('unconfortable_logo', {type: 'scenario-sync',duration: 20, forceRender: false ,animTimingFunction:Vivus.EASE})
232
-
233
- </script>
234
-
235
- </body>
241
+ ```css
242
+
243
+
244
+
245
+ /*ハンバーガー用トリガーを含むヘッダーnav(ロゴとトリガー)*/
246
+
247
+ #the-nav{
248
+
249
+ padding-top: 15px;
250
+
251
+ position:fixed;
252
+
253
+ z-index: 3;
254
+
255
+ top:0vh;
256
+
257
+ width: 100%;
258
+
259
+ }
260
+
261
+
262
+
263
+ /*ハンバーガー用トリガー*/
264
+
265
+ .menu-trigger,
266
+
267
+ .menu-trigger span {
268
+
269
+ display: inline-block;
270
+
271
+ transition: all .4s;
272
+
273
+ box-sizing: border-box;
274
+
275
+ }
276
+
277
+ .menu-trigger {
278
+
279
+ position: relative;
280
+
281
+ height: 30px;
282
+
283
+ width: 30px;
284
+
285
+ left: 30%;
286
+
287
+ z-index: 12;
288
+
289
+ }
290
+
291
+ .menu-trigger span {
292
+
293
+ position: absolute;
294
+
295
+ height: 1px;
296
+
297
+ background-color: #000000;
298
+
299
+ }
300
+
301
+ .menu-trigger span:nth-of-type(1) {
302
+
303
+ top: 15px;
304
+
305
+ width: 100%;
306
+
307
+ }
308
+
309
+ .menu-trigger span:nth-of-type(2) {
310
+
311
+ top: 25px;
312
+
313
+ width: 100%;
314
+
315
+ }
316
+
317
+
318
+
319
+ .menu-trigger.active span:nth-of-type(1) {
320
+
321
+ position: absolute;
322
+
323
+ -webkit-transform: translateY(5px) rotate(-45deg);
324
+
325
+ transform: translateY(5px) rotate(-45deg);
326
+
327
+ }
328
+
329
+
330
+
331
+ .menu-trigger.active span:nth-of-type(2) {
332
+
333
+ position: absolute;
334
+
335
+ -webkit-transform: translateY(-5px) rotate(45deg);
336
+
337
+ transform: translateY(-5px) rotate(45deg);
338
+
339
+
340
+
341
+ }
342
+
343
+
344
+
345
+ .stick-under-line span{
346
+
347
+ border-bottom: 1px solid #000;
348
+
349
+ display: block;
350
+
351
+ height: 27px;
352
+
353
+ text-align: right;
354
+
355
+ }
356
+
357
+
358
+
359
+ /*ハンバーガーメニュー*/
360
+
361
+ nav.globalMenuSp {
362
+
363
+ position: fixed;
364
+
365
+ z-index: 2;
366
+
367
+ top: 0;
368
+
369
+ left: 0;
370
+
371
+ background: #fff;
372
+
373
+ color: #000;
374
+
375
+ text-align: center;
376
+
377
+ transform: translateY(-100vh);
378
+
379
+ transition: all 0.6s;
380
+
381
+ width: 100%;
382
+
383
+ -webkit-overflow-scrolling:touch;
384
+
385
+ }
386
+
387
+
388
+
389
+ nav.globalMenuSp ul {
390
+
391
+ background: brown;
392
+
393
+ margin: 0 auto;
394
+
395
+ padding: 100px 80px;
396
+
397
+ width: 100%;
398
+
399
+ height: 100vh;
400
+
401
+ }
402
+
403
+
404
+
405
+ nav.globalMenuSp ul li {
406
+
407
+ font-size: 1.1em;
408
+
409
+ list-style-type: none;
410
+
411
+ padding: 0;
412
+
413
+ width: 100%;
414
+
415
+ border-bottom: 1px dotted #333;
416
+
417
+ }
418
+
419
+
420
+
421
+ nav.globalMenuSp ul li:last-child {
422
+
423
+ padding-bottom: 0;
424
+
425
+ border-bottom: none;
426
+
427
+ }
428
+
429
+
430
+
431
+ nav.globalMenuSp ul li a {
432
+
433
+ display: block;
434
+
435
+ color: #000;
436
+
437
+ padding: 1em 0;
438
+
439
+ }
440
+
441
+
442
+
443
+ /* activeを当てて表示させる */
444
+
445
+ nav.globalMenuSp.active {
446
+
447
+ transform: translateY(0vh);
448
+
449
+ }
450
+
451
+
236
452
 
237
453
  ```
238
454
 
239
455
 
240
456
 
241
- ```css
242
-
243
-
244
-
245
- /*ハンバーガー用トリガーを含むヘッダーnav(ロゴとトリガー)*/
246
-
247
- #the-nav{
248
-
249
- padding-top: 15px;
250
-
251
- position:fixed;
252
-
253
- z-index: 3;
254
-
255
- top:0vh;
256
-
257
- width: 100%;
258
-
259
- }
260
-
261
-
262
-
263
- /*ハンバーガー用トリガー*/
264
-
265
- .menu-trigger,
266
-
267
- .menu-trigger span {
268
-
269
- display: inline-block;
270
-
271
- transition: all .4s;
272
-
273
- box-sizing: border-box;
274
-
275
- }
276
-
277
- .menu-trigger {
278
-
279
- position: relative;
280
-
281
- height: 30px;
282
-
283
- width: 30px;
284
-
285
- left: 30%;
286
-
287
- z-index: 12;
288
-
289
- }
290
-
291
- .menu-trigger span {
292
-
293
- position: absolute;
294
-
295
- height: 1px;
296
-
297
- background-color: #000000;
298
-
299
- }
300
-
301
- .menu-trigger span:nth-of-type(1) {
302
-
303
- top: 15px;
304
-
305
- width: 100%;
306
-
307
- }
308
-
309
- .menu-trigger span:nth-of-type(2) {
310
-
311
- top: 25px;
312
-
313
- width: 100%;
314
-
315
- }
316
-
317
-
318
-
319
- .menu-trigger.active span:nth-of-type(1) {
320
-
321
- position: absolute;
322
-
323
- -webkit-transform: translateY(5px) rotate(-45deg);
324
-
325
- transform: translateY(5px) rotate(-45deg);
326
-
327
- }
328
-
329
-
330
-
331
- .menu-trigger.active span:nth-of-type(2) {
332
-
333
- position: absolute;
334
-
335
- -webkit-transform: translateY(-5px) rotate(45deg);
336
-
337
- transform: translateY(-5px) rotate(45deg);
338
-
339
-
340
-
341
- }
342
-
343
-
344
-
345
- .stick-under-line span{
346
-
347
- border-bottom: 1px solid #000;
348
-
349
- display: block;
350
-
351
- height: 27px;
352
-
353
- text-align: right;
354
-
355
- }
356
-
357
-
358
-
359
- /*ハンバーガーメニュー*/
360
-
361
- nav.globalMenuSp {
362
-
363
- position: fixed;
364
-
365
- z-index: 2;
366
-
367
- top: 0;
368
-
369
- left: 0;
370
-
371
- background: #fff;
372
-
373
- color: #000;
374
-
375
- text-align: center;
376
-
377
- transform: translateY(-100vh);
378
-
379
- transition: all 0.6s;
380
-
381
- width: 100%;
382
-
383
- -webkit-overflow-scrolling:touch;
384
-
385
- }
386
-
387
-
388
-
389
- nav.globalMenuSp ul {
390
-
391
- background: brown;
392
-
393
- margin: 0 auto;
394
-
395
- padding: 100px 80px;
396
-
397
- width: 100%;
398
-
399
- height: 100vh;
400
-
401
- }
402
-
403
-
404
-
405
- nav.globalMenuSp ul li {
406
-
407
- font-size: 1.1em;
408
-
409
- list-style-type: none;
410
-
411
- padding: 0;
412
-
413
- width: 100%;
414
-
415
- border-bottom: 1px dotted #333;
416
-
417
- }
418
-
419
-
420
-
421
- nav.globalMenuSp ul li:last-child {
422
-
423
- padding-bottom: 0;
424
-
425
- border-bottom: none;
426
-
427
- }
428
-
429
-
430
-
431
- nav.globalMenuSp ul li a {
432
-
433
- display: block;
434
-
435
- color: #000;
436
-
437
- padding: 1em 0;
438
-
439
- }
440
-
441
-
442
-
443
- /* activeを当てて表示させる */
444
-
445
- nav.globalMenuSp.active {
446
-
447
- transform: translateY(0vh);
448
-
449
- }
450
-
451
-
452
-
453
- ```
454
-
455
-
456
-
457
457
  ### 試したこと
458
458
 
459
459
 

1

html下部にjqueryを書き加えました。

2019/07/09 14:39

投稿

c_y
c_y

スコア12

test CHANGED
File without changes
test CHANGED
@@ -148,19 +148,89 @@
148
148
 
149
149
  </nav>
150
150
 
151
+
152
+
153
+ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
154
+
151
155
  <script src="js/jquery-3.2.1.min.js"></script>
152
156
 
157
+
158
+
159
+ <!-- Include all compiled plugins (below), or include individual files as needed -->
160
+
153
161
  <script src="js/popper.min.js"></script>
154
162
 
155
163
  <script src="js/bootstrap-4.0.0.js"></script>
156
164
 
165
+ <!--vivus js-->
166
+
167
+ <!-- <script src="js/vivus.min.js"></script> -->
168
+
169
+ <!--slick js-->
170
+
171
+ <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
172
+
173
+ <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
174
+
175
+ <script type="text/javascript" src="slick/slick.min.js"></script>
176
+
177
+
178
+
157
179
  <script>
158
180
 
181
+ $(function(){
182
+
183
+ var current_scrollY;
184
+
185
+ $('.menu-trigger').on('click', function() {
186
+
187
+ $(this).toggleClass('active');
188
+
189
+ current_scrollY = $( window ).scrollTop();
190
+
191
+ if ($(this).hasClass('active')) {
192
+
193
+ $('.globalMenuSp').addClass('active');
194
+
195
+ $( 'body' ).css( {
196
+
197
+ position: 'fixed',
198
+
199
+ width: '100%',
200
+
201
+ //top位置をその時点のスクロール量分だけ上にずらす
202
+
203
+ top: -1 * current_scrollY
204
+
205
+ } );
206
+
159
- //ここに上記のjqueryを記述しています
207
+ // return false;
208
+
160
-
209
+ } else {
210
+
211
+ $('.globalMenuSp').removeClass('active');
212
+
213
+ $( 'body' ).attr( { style: '' } );
214
+
215
+ $("html,body").scrollTop(current_scrollY);
216
+
217
+ }
218
+
219
+
220
+
221
+ });
222
+
223
+ });
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+ new Vivus('unconfortable_logo', {type: 'scenario-sync',duration: 20, forceRender: false ,animTimingFunction:Vivus.EASE})
232
+
161
- <script>
233
+ </script>
162
-
163
- <script src="js/vivus.min.js"></script>
164
234
 
165
235
  </body>
166
236