回答編集履歴

2

コード修正

2020/02/15 06:24

投稿

hatena19
hatena19

スコア33715

test CHANGED
@@ -104,7 +104,7 @@
104
104
 
105
105
  <ul>
106
106
 
107
- <li><a class="current" href="https://jin-demo.jp/demo-4">HOME</a></li>
107
+ <li><a class="current" href="#">HOME</a></li>
108
108
 
109
109
  <li><a href="#">PROFILE</a></li>
110
110
 

1

サンプル追記

2020/02/15 06:24

投稿

hatena19
hatena19

スコア33715

test CHANGED
@@ -92,4 +92,126 @@
92
92
 
93
93
 
94
94
 
95
- 具体的にどうしたいのか不明確なのでこれはパス。
95
+ ~~具体的にどうしたいのか不明確なのでこれはパス。~~
96
+
97
+ 「追いかけてくる」と呈示されているjQueryから、下記のようなことかと推測。
98
+
99
+
100
+
101
+ ```html
102
+
103
+ <div class="menu">
104
+
105
+ <ul>
106
+
107
+ <li><a class="current" href="https://jin-demo.jp/demo-4">HOME</a></li>
108
+
109
+ <li><a href="#">PROFILE</a></li>
110
+
111
+ <li><a href="#">SERVICE</a></li>
112
+
113
+ <li><a href="#">REVIEW</a></li>
114
+
115
+ <li><a href="#">CONTACT</a></li>
116
+
117
+ </ul>
118
+
119
+ <span></span>
120
+
121
+ </div>
122
+
123
+ ```
124
+
125
+ ```css
126
+
127
+ .menu {
128
+
129
+ display: flex;
130
+
131
+ justify-content: center;
132
+
133
+ }
134
+
135
+ .menu ul {
136
+
137
+ display: flex;
138
+
139
+ margin: 10px 20px;
140
+
141
+ }
142
+
143
+ .menu li{
144
+
145
+ padding: 10px 30px;
146
+
147
+ }
148
+
149
+ .menu span {
150
+
151
+ position: absolute;
152
+
153
+ bottom: 0;
154
+
155
+ height: 3px;
156
+
157
+ background-color: black;
158
+
159
+ }
160
+
161
+ ```
162
+
163
+ ```js
164
+
165
+ var menuCurrent = $('.menu .current'),
166
+
167
+ cssCurrent={
168
+
169
+ width: menuCurrent.outerWidth(),
170
+
171
+ left: menuCurrent.position().left
172
+
173
+ };
174
+
175
+ $(window).on('load resize', function () {
176
+
177
+ $('.menu span').css({
178
+
179
+ width: menuCurrent.outerWidth(),
180
+
181
+ left: menuCurrent.position().left
182
+
183
+ });
184
+
185
+ });
186
+
187
+ $('.menu li').hover(
188
+
189
+ function () {
190
+
191
+ $('.menu span').stop().animate({
192
+
193
+ width: $(this).children().outerWidth(),
194
+
195
+ left: $(this).children().position().left
196
+
197
+ }, 'fast');
198
+
199
+ },
200
+
201
+ function () {
202
+
203
+ $('.menu span').stop().animate({
204
+
205
+ width: menuCurrent.outerWidth(),
206
+
207
+ left: menuCurrent.position().left
208
+
209
+ }, 'fast');
210
+
211
+ }
212
+
213
+ );
214
+
215
+ ```
216
+
217
+ [動作確認用サンプル](https://codepen.io/hatena19/pen/OJVMKWV)