回答編集履歴

3

テキスト修正

2020/09/10 16:33

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -208,7 +208,7 @@
208
208
 
209
209
  <title>Q290782</title>
210
210
 
211
- <link rel="stylesheet" href="styles.css?x">
211
+ <link rel="stylesheet" href="styles.css">
212
212
 
213
213
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
214
214
 

2

テキスト修正

2020/09/10 16:33

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -121,3 +121,157 @@
121
121
 
122
122
 
123
123
  参考になれば幸いです。
124
+
125
+
126
+
127
+
128
+
129
+ ## 追記
130
+
131
+
132
+
133
+ コメントから頂きました要件を満たせそうなものを試作してみました。こちらは css order は使わず、JQuery UI の [toggle](https://api.jqueryui.com/toggle/) を使うことによって、最下行のみが表示されているときに、最下行をクリックすると、他のアイテムが上方向に展開されます。また、最下行のアイテムを囲む`ul`を、スライド表示させる他のアイテム用の`ul`と別にすることで、最下行はアニメーションの影響を受けないようにしています。
134
+
135
+
136
+
137
+ ### styles.css
138
+
139
+
140
+
141
+ ```css
142
+
143
+ .keywordTab {
144
+
145
+ display: flex;
146
+
147
+ flex-direction: column;
148
+
149
+ justify-content: space-around;
150
+
151
+ align-items: center;
152
+
153
+ margin: 0 auto;
154
+
155
+ list-style: none;
156
+
157
+ }
158
+
159
+
160
+
161
+ .sliderWrapper { height: calc(52px * 5); }
162
+
163
+
164
+
165
+ .tabLabel {
166
+
167
+ display: flex;
168
+
169
+ opacity: 0.6;
170
+
171
+ width: calc(300 * (100vw / 375));
172
+
173
+ height: 50px;
174
+
175
+ font-size: 1.5rem;
176
+
177
+ justify-content: center;
178
+
179
+ align-items: center;
180
+
181
+ cursor: pointer;
182
+
183
+ border-bottom: 0.1rem solid #967F4F;
184
+
185
+ color: #000;
186
+
187
+ }
188
+
189
+
190
+
191
+ ```
192
+
193
+
194
+
195
+ ### index.html
196
+
197
+
198
+
199
+ ```html
200
+
201
+ <!DOCTYPE html>
202
+
203
+ <html lang="ja">
204
+
205
+ <head>
206
+
207
+ <meta charset="UTF-8">
208
+
209
+ <title>Q290782</title>
210
+
211
+ <link rel="stylesheet" href="styles.css?x">
212
+
213
+ <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
214
+
215
+ <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
216
+
217
+ <script>
218
+
219
+ $(function() {
220
+
221
+ $(".tabLabel").on("click", function() {
222
+
223
+ const bottomItem = $(".bottom-item .tabLabel").get(0);
224
+
225
+ if (this !== bottomItem) {
226
+
227
+ $(".bottom-item").append(this);
228
+
229
+ $(".slider").append(bottomItem);
230
+
231
+ }
232
+
233
+ $(".slider").toggle('slide', { direction: 'down' });
234
+
235
+ });
236
+
237
+ });
238
+
239
+ </script>
240
+
241
+ </head>
242
+
243
+ <body>
244
+
245
+ <div class="sliderWrapper">
246
+
247
+ <ul class="keywordTab slider">
248
+
249
+ <li class="tabLabel">ジャンル5</li>
250
+
251
+ <li class="tabLabel">ジャンル4</li>
252
+
253
+ <li class="tabLabel">ジャンル3</li>
254
+
255
+ <li class="tabLabel">ジャンル2</li>
256
+
257
+ <li class="tabLabel">ジャンル1</li>
258
+
259
+ </ul>
260
+
261
+ </div>
262
+
263
+ <ul class="keywordTab bottom-item">
264
+
265
+ <li class="tabLabel">全てのジャンル</li>
266
+
267
+ </ul>
268
+
269
+ </body>
270
+
271
+ </html>
272
+
273
+ ```
274
+
275
+
276
+
277
+ - **動作確認用 codepen:** [https://codepen.io/jun68ykt/pen/xxVWaLg](https://codepen.io/jun68ykt/pen/xxVWaLg)

1

テキスト修正

2020/09/10 16:29

投稿

jun68ykt
jun68ykt

スコア9058

test CHANGED
@@ -80,7 +80,7 @@
80
80
 
81
81
 
82
82
 
83
- タブが閉じた状態から開く状態に移行する際に、クリックされたリストアイテムのcss orderをリストアイテムの個数と同数にすることで最るようにし、それにあわせて、その他のアイテムのcss order のうち、変更が必要なもの新たな値で更新します。
83
+ タブが閉じた状態から開く状態に移行する際に、クリックされたリストアイテムが見た目上、一番下にるように css order を更新します。
84
84
 
85
85
 
86
86
 
@@ -96,23 +96,19 @@
96
96
 
97
97
  + if (isClosed) {
98
98
 
99
- + const clickedOrder = $(this).css('order');
99
+ + $(this).css({ order: numItems + 1 });
100
100
 
101
- + $(this).css({ order: numItems });
101
+ + $(".tabLabel")
102
102
 
103
- + const that = this;
103
+ + .sort((e1, e2) => e1.style.order - e2.style.order)
104
104
 
105
- + $(".tabLabel").each(function() {
105
+ + .each(function(i) {
106
106
 
107
- + const order = $(this).css('order');
107
+ + $(this).css({ order: i + 1 });
108
108
 
109
- + if (order > clickedOrder && that !== this)
109
+ + });
110
110
 
111
- + $(this).css({ order: order - 1 });
112
-
113
- + });
114
-
115
- + }
111
+ + }
116
112
 
117
113
  });
118
114
 
@@ -120,7 +116,7 @@
120
116
 
121
117
 
122
118
 
123
- - **動作確認用 codepen:** [https://codepen.io/jun68ykt/pen/NWNYrEB](https://codepen.io/jun68ykt/pen/NWNYrEB?editors=1010)
119
+ - **動作確認用 codepen:** [https://codepen.io/jun68ykt/pen/RwaMGrQ](https://codepen.io/jun68ykt/pen/RwaMGrQ?editors=1010)
124
120
 
125
121
 
126
122