回答編集履歴

1

このコメントは間違いです

2019/11/22 01:39

投稿

hukumarukun
test CHANGED
@@ -1 +1,193 @@
1
+ 公開できる範囲で、解決したJSの記述を公開します
2
+
3
+ 記述したコード
4
+
5
+
6
+
7
+ ```ここに言語を入力
8
+
9
+ <div class="section fixed-top header_wrap">
10
+
11
+ <div class="header">
12
+
13
+ <div id="logo"><a href="/"><img src="" alt=""></a></div>
14
+
15
+
16
+
17
+ <div class="spmenu_wrap">
18
+
19
+ <div class="nav-button">
20
+
21
+ <div class="nav_wrap">
22
+
23
+ <span></span>
24
+
25
+ <span></span>
26
+
27
+ <span></span>
28
+
29
+ </div>
30
+
31
+ </div>
32
+
33
+ <nav class="nav-wrap nav_wrap_menu">
34
+
35
+
36
+
37
+ <div class="nav_box">
38
+
39
+ <ul class="navbox nav-item nav-tabs">
40
+
41
+ <li class="nav-item dropdown"><a href="/about/" class="nav-link dropdown-toggle" id="company">会社情報</a>
42
+
43
+ <div class="dropdown-menu">
44
+
45
+ <ul>
46
+
47
+ <li><a class="dropdown-item anchorlink" href="/about/index.html#company_about"><span><i class="fa fa-angle-right" aria-hidden="true"></i>A</span></a></li>
48
+
49
+ <li><a class="dropdown-item anchorlink" href="/about/index.html#history"><span><i class="fa fa-angle-right" aria-hidden="true"></i>B</span></a></li>
50
+
51
+ </ul>
52
+
53
+ </div>
54
+
55
+
56
+
57
+ <div class="spmenu">
58
+
59
+ <ul>
60
+
61
+ <li><a class="anchorlink" href="/about/index.html#company_about"><i class="fa fa-angle-right" aria-hidden="true"></i>A</a></li>
62
+
63
+ <li><a class="anchorlink" href="/about/index.html#history"><i class="fa fa-angle-right" aria-hidden="true"></i>B</a></li>
64
+
65
+ </ul>
66
+
67
+ </div>
68
+
69
+ </li>
70
+
71
+ </ul>
72
+
73
+ </div>
74
+
75
+ </nav>
76
+
77
+ </div>
78
+
79
+ <!-- spmenu_wrap -->
80
+
81
+ </div>
82
+
83
+ </div>
84
+
85
+ ```
86
+
87
+
88
+
89
+ 記述したJS
90
+
91
+
92
+
93
+ $(function() {
94
+
95
+
96
+
97
+ var H_nav = $(".header").height();
98
+
99
+
100
+
101
+ function pagelink(heightnum) {
102
+
103
+ var headerH = heightnum;
104
+
105
+
106
+
107
+ $(".anchorlink").click(function() {
108
+
109
+ if ($(".nav-button .nav_wrap").hasClass("active")) {
110
+
111
+ $(".nav-button .nav_wrap").removeClass("active");
112
+
113
+ $(".nav-wrap").addClass("close");
114
+
115
+ $(".nav-wrap").removeClass("open");
116
+
117
+ }
118
+
119
+
120
+
121
+ var headerHeight = $(".header").height(); //ヘッダの高さを計測
122
+
123
+
124
+
125
+ var href = $(this).attr("href");
126
+
127
+ // window.alert(href);
128
+
129
+ var check_inner = href.indexOf('#');
130
+
131
+ if (check_inner < 1) {
132
+
1
- このコメトは間違いすこのコメント間違ですこコメントは間違いすこのコメトは間違いです
133
+ location.href = href; //ページ内リではいので、直ぐリ
134
+
135
+ }
136
+
137
+ else {
138
+
139
+ location.replace(href);
140
+
141
+ }
142
+
143
+
144
+
145
+ var url = $(location).attr("href");
146
+
147
+ var url_sp = url.split("#");
148
+
149
+ var hash = "#" + url_sp[url_sp.length - 1];
150
+
151
+ var target = $(hash);
152
+
153
+ var position = target.offset().top - headerH -15; //高さ+15pxの余白を引く
154
+
155
+ $("html, body").animate({ scrollTop: position }, 300, "swing");
156
+
157
+
158
+
159
+ });
160
+
161
+
162
+
163
+ /* outpagelink */
164
+
165
+ var url = $(location).attr("href");
166
+
167
+ if (url.indexOf("#") != -1) {
168
+
169
+ var url_sp = url.split("#");
170
+
171
+ var hash = "#" + url_sp[url_sp.length - 1];
172
+
173
+ var target = $(hash);
174
+
175
+ var position = target.offset().top - headerH -15;
176
+
177
+ $("html, body").animate({ scrollTop: position }, 300, "swing");
178
+
179
+ return false;
180
+
181
+ }
182
+
183
+ }
184
+
185
+
186
+
187
+ pagelink(H_nav);
188
+
189
+
190
+
191
+ });
192
+
193
+ ```