質問編集履歴

3

html修正

2019/08/28 03:26

投稿

nakajima4
nakajima4

スコア11

test CHANGED
File without changes
test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  ```testhtml
70
70
 
71
- <p id="">ダミーテキスト</p>
71
+ <p class="page-15-p">ダミーテキスト</p>
72
72
 
73
73
  <!--タブ-->
74
74
 

2

jsの修正

2019/08/28 03:26

投稿

nakajima4
nakajima4

スコア11

test CHANGED
File without changes
test CHANGED
@@ -192,12 +192,16 @@
192
192
 
193
193
  ```js
194
194
 
195
- <script type="text/javascript">
195
+ <script type="text/javascript">
196
196
 
197
197
  //タブ操作
198
198
 
199
199
  jQuery(function($){
200
200
 
201
+ var target = $('.page-15-p');
202
+
203
+ var position = target.offset().top;
204
+
201
205
  $('.tab').click(function(){
202
206
 
203
207
  $('.is-active').removeClass('is-active');
@@ -216,13 +220,97 @@
216
220
 
217
221
  });
218
222
 
223
+ $('.tab1').click(function(){
224
+
225
+ $('.is-active').removeClass('is-active');
226
+
227
+ $('#tab1').addClass('is-active');
228
+
229
+ $('#tab1').addClass('is-show');
230
+
231
+ $('body,html').stop().animate({scrollTop:position}, 500);
232
+
233
+ });
234
+
235
+ $('.tab2').click(function(){
236
+
237
+ $('.is-active').removeClass('is-active');
238
+
239
+ $('#tab2').addClass('is-active');
240
+
241
+ $('#tab2').addClass('is-show');
242
+
243
+ $('body,html').stop().animate({scrollTop:position}, 500);
244
+
245
+ });
246
+
247
+ $('.tab3').click(function(){
248
+
249
+ $('.is-active').removeClass('is-active');
250
+
251
+ $('#tab3').addClass('is-active');
252
+
253
+ $('#tab3').addClass('is-show');
254
+
255
+ $('body,html').stop().animate({scrollTop:position}, 500);
256
+
257
+ });
258
+
259
+ $('.tab4').click(function(){
260
+
261
+ $('.is-active').removeClass('is-active');
262
+
263
+ $('#tab4').addClass('is-active');
264
+
265
+ $('#tab4').addClass('is-show');
266
+
267
+ $('body,html').stop().animate({scrollTop:position}, 500);
268
+
269
+ });
270
+
271
+ $('.tab5').click(function(){
272
+
273
+ $('.is-active').removeClass('is-active');
274
+
275
+ $('#tab5').addClass('is-active');
276
+
277
+ $('#tab5').addClass('is-show');
278
+
279
+ $('body,html').stop().animate({scrollTop:position}, 500);
280
+
281
+ });
282
+
283
+ $('.tab6').click(function(){
284
+
285
+ $('.is-active').removeClass('is-active');
286
+
287
+ $('#tab6').addClass('is-active');
288
+
289
+ $('#tab6').addClass('is-show');
290
+
291
+ $('body,html').stop().animate({scrollTop:position}, 500);
292
+
293
+ });
294
+
295
+ $('.tab7').click(function(){
296
+
297
+ $('.is-active').removeClass('is-active');
298
+
299
+ $('#tab7').addClass('is-active');
300
+
301
+ $('#tab7').addClass('is-show');
302
+
303
+ $('body,html').stop().animate({scrollTop:position}, 500);
304
+
305
+ return false;
306
+
307
+ });
308
+
219
309
  });
220
310
 
221
311
  </script>
222
312
 
223
-
224
-
225
- <script type="text/javascript">
313
+ <script type="text/javascript">
226
314
 
227
315
  //タブ内から別タブへのページ内リンク
228
316
 
@@ -238,15 +326,21 @@
238
326
 
239
327
  $('.panel:nth-child(3)').addClass('is-show');
240
328
 
329
+ var target = $('#page-link1');
330
+
331
+ var position = target.offset().top;
332
+
333
+ $('body,html').stop().animate({scrollTop:position}, 500);
334
+
335
+ return false;
336
+
241
337
  });
242
338
 
243
339
  });
244
340
 
245
341
  </script>
246
342
 
247
-
248
-
249
- <script>
343
+ <script>
250
344
 
251
345
  // タブへのダイレクトリンク
252
346
 
@@ -298,4 +392,98 @@
298
392
 
299
393
  </script>
300
394
 
395
+ <script>
396
+
397
+ jQuery(function($){
398
+
399
+ $(document).ready(function(){
400
+
401
+ //URLのハッシュ値を取得
402
+
403
+ var urlHash = location.hash;
404
+
405
+ //ハッシュ値があればページ内スクロール
406
+
407
+ if(urlHash) {
408
+
409
+ //スクロールを0に戻す
410
+
411
+ $('body,html').stop().scrollTop(0);
412
+
413
+ setTimeout(function () {
414
+
415
+ //ロード時の処理を待ち、時間差でスクロール実行
416
+
417
+ scrollToAnker(urlHash) ;
418
+
419
+ }, 100);
420
+
421
+ }
422
+
423
+
424
+
425
+ //通常のクリック時
426
+
427
+ $('.icon1,.icon2,.icon3,.icon4,.icon5,.icon6,.icon7').click(function() {
428
+
429
+ //ページ内リンク先を取得
430
+
431
+ var href= $(this).attr("href");
432
+
433
+ //リンク先が#か空だったらhtmlに
434
+
435
+ var hash = href == "#" || href == "" ? 'html' : href;
436
+
437
+ //スクロール実行
438
+
439
+ scrollToAnker(hash);
440
+
441
+ //リンク無効化
442
+
443
+ return false;
444
+
445
+ });
446
+
447
+
448
+
449
+ // 関数:スムーススクロール
450
+
451
+ // 指定したアンカー(#ID)へアニメーションでスクロール
452
+
453
+ function scrollToAnker(hash) {
454
+
455
+ var target = $('.page-15-p');
456
+
457
+ var position = target.offset().top;
458
+
459
+ $('body,html').stop().animate({scrollTop:position}, 500);
460
+
461
+ }
462
+
463
+ })
464
+
465
+ });
466
+
467
+ </script>
468
+
469
+ <script>
470
+
471
+ jQuery(function($){
472
+
473
+ // liのうち、href属性が指定されているものを取得
474
+
475
+ $('li[href]').click(function(){
476
+
477
+ let href = $(this).attr('href');
478
+
479
+ location.href = href;
480
+
481
+ // window.open(href);
482
+
483
+ });
484
+
485
+ });
486
+
487
+ </script>
488
+
301
489
  ```

1

説明の修正

2019/08/28 03:24

投稿

nakajima4
nakajima4

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,11 +1,7 @@
1
1
  idでページリンクさせた場合にURLの末尾に#tab1とついてしまうのですが、URLにアンカーリンクを付加させないでtest.htmlのみにしたく考えています。
2
2
 
3
- history.replaceState(null, '', location.pathname + location.search);で書き換えしたところURLにアンカーリンクを付加させないようになったのですが、リンク先がページのトップになってしまいました。
4
-
5
3
  URLにアンカーリンクを付加させないで目的の場所へ移動させたいです。
6
4
 
7
- また、タブへのダイレクトリンクをさせた場合のジャンプ先の位置をネガティブマージンで調整することは可能でしょうか
8
-
9
5
  ```indexhtml
10
6
 
11
7
  <div class="flex">
@@ -276,8 +272,6 @@
276
272
 
277
273
  var tabbar = tabname - 1;
278
274
 
279
- history.replaceState(null, '', location.pathname + location.search);
280
-
281
275
  }
282
276
 
283
277
  $(function() {