質問編集履歴

4

解決したいことの修正

2019/05/09 05:19

投稿

kakeru99
kakeru99

スコア17

test CHANGED
@@ -1 +1 @@
1
- スクリプトを早く処理して素化したい
1
+ スクリプトを簡潔に書きたい
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ### 解決したいこと
2
2
 
3
- スクリプト自体は動くのですがここからもっとシンプルに早く処理できるように書きたいのですがどのように書けばもっと簡素化できるでしょうか?
3
+ スクリプト自体は動くのですがここからもっとシンプルに簡潔に書きたいのですがどのように書けばもっと簡素化できるでしょうか?
4
4
 
5
5
  また簡素化できるポイントを見つけるコツなどはありますでしょうか?
6
6
 

3

HTML・CSSの追加・JSの修正

2019/05/09 05:19

投稿

kakeru99
kakeru99

スコア17

test CHANGED
File without changes
test CHANGED
@@ -10,109 +10,263 @@
10
10
 
11
11
 
12
12
 
13
+ ```html
14
+
15
+ <div class="btn_list list01">
16
+
17
+ <p class="btn">ボタンA</p>
18
+
19
+ <dl>
20
+
21
+ <dt>コンテンツ</dt>
22
+
23
+ <dd>コンテンツテキスト</dd>
24
+
25
+ </dl>
26
+
27
+ </div>
28
+
29
+ <!-- btn_list -->
30
+
31
+
32
+
33
+ <div class="btn_list list02">
34
+
35
+ <p class="btn">ボタンB</p>
36
+
37
+ <dl>
38
+
39
+ <dt>コンテンツ</dt>
40
+
41
+ <dd>コンテンツテキスト</dd>
42
+
43
+ <dd>コンテンツテキスト</dd>
44
+
45
+ <dd>コンテンツテキスト</dd>
46
+
47
+ </dl>
48
+
49
+ </div>
50
+
51
+ <!-- btn_list -->
52
+
53
+
54
+
55
+ <div id="wrap">
56
+
57
+ <div class="option_wrap">
58
+
59
+ <select>
60
+
61
+ <optgroup label="">
62
+
63
+ <option value="a">AAA</option>
64
+
65
+ <option value="b">BBB</option>
66
+
67
+ <option value="c">CCC</option>
68
+
69
+ </optgroup>
70
+
71
+ </select>
72
+
73
+ </div>
74
+
75
+
76
+
77
+ <div class="option_wrap">
78
+
79
+ <select>
80
+
81
+ <optgroup label="">
82
+
83
+ <option value="a">AAA</option>
84
+
85
+ <option value="b">BBB</option>
86
+
87
+ <option value="c">CCC</option>
88
+
89
+ </optgroup>
90
+
91
+ </select>
92
+
93
+ </div>
94
+
95
+
96
+
97
+ <div class="option_wrap">
98
+
99
+ <select>
100
+
101
+ <optgroup label="">
102
+
103
+ <option value="a">AAA</option>
104
+
105
+ <option value="b">BBB</option>
106
+
107
+ <option value="c">CCC</option>
108
+
109
+ </optgroup>
110
+
111
+ </select>
112
+
113
+ </div>
114
+
115
+ </div>
116
+
117
+ ```
118
+
119
+
120
+
121
+ ```css
122
+
123
+
124
+
125
+ body{
126
+
127
+ padding-top:3vw;
128
+
129
+ }
130
+
131
+ .btn{
132
+
133
+ padding:15px;
134
+
135
+ text-align:center;
136
+
137
+ color:#000;
138
+
139
+ background: #ccc;
140
+
141
+ border:1px solid #000;
142
+
143
+ margin:0;
144
+
145
+ }
146
+
147
+ .btn_list dl{
148
+
149
+ display: none;
150
+
151
+ margin:0;
152
+
153
+ }
154
+
155
+ #wrap .option_wrap{
156
+
157
+ position: absolute;
158
+
159
+ width: 100%;
160
+
161
+ left:50%;
162
+
163
+ margin-left: -50%;
164
+
165
+ }
166
+
167
+ #wrap .option_wrap option{
168
+
169
+ width: 100%;
170
+
171
+ }
172
+
173
+ #wrap .option_wrap:nth-of-type(1){
174
+
175
+ top:0;
176
+
177
+ }
178
+
179
+ #wrap .option_wrap:nth-of-type(2){
180
+
181
+ top:20vw;
182
+
183
+ }
184
+
185
+ #wrap .option_wrap:nth-of-type(3){
186
+
187
+ top:30vw;
188
+
189
+ }
190
+
191
+ ```
192
+
193
+
194
+
13
195
  ```javascript
14
196
 
15
197
  <script>
16
198
 
17
199
 
18
200
 
19
- $(function(){
20
-
21
- const WindowsWidth = $(window).width();
22
-
23
- const BoxHeight01 = parseInt($(".conditions_list.list01 dl").innerHeight());
24
-
25
- const BoxHeight02 = parseInt($(".conditions_list.list02 dl").innerHeight());
26
-
27
- const AddVw01 = (BoxHeight01 / WindowsWidth)*100;
28
-
29
- const AddVw02 = (BoxHeight02 / WindowsWidth)*100;
30
-
31
-
32
-
33
- const OptionNth01 = parseInt($("#customItemWrap #itemBtn .option select:nth-of-type(1)").css('top'));
34
-
35
- const OptionNth02 = parseInt($("#customItemWrap #itemBtn .option select:nth-of-type(2)").css('top'));
36
-
37
- const OptionNth03 = parseInt($("#customItemWrap #itemBtn .option select:nth-of-type(3)").css('top'));
38
-
39
- const Input1 = parseInt($("#headDescription #M_nameInput1").css('top'));
40
-
41
- const Arrow2 = parseInt($("p.arrow02").css('top'));
42
-
43
-
44
-
45
- const OptionNthVw01 = (OptionNth01 / WindowsWidth)*100;
46
-
47
- const OptionNthVw02 = (OptionNth02 / WindowsWidth)*100;
48
-
49
- const OptionNthVw03 = (OptionNth03 / WindowsWidth)*100;
50
-
51
- const InputNthVw01 = (Input1 / WindowsWidth)*100;
52
-
53
- const ArrowNthVw02 = (Arrow2 / WindowsWidth)*100;
54
-
55
-
56
-
57
- const f_VwTotal01 = AddVw01 + OptionNthVw01;
58
-
59
- const f_VwTotal02 = AddVw01 + OptionNthVw02;
60
-
61
- const f_VwTotal03 = AddVw01 + OptionNthVw03;
62
-
63
- const f_InputTotal01 = AddVw01 + InputNthVw01;
64
-
65
- const f_ArrowTotal02 = AddVw01 + ArrowNthVw02;
66
-
67
-
68
-
69
-
70
-
71
- const s_VwTotal02 = AddVw02 + OptionNthVw02;
72
-
73
- const s_VwTotal03 = AddVw02 + OptionNthVw03;
74
-
75
-
76
-
77
- $('.conditions_list.list01 dl').css('display','none');
78
-
79
- $('.conditions_list.list02 dl').css('display','none');
80
-
81
- $("p.tit_pat01").on("click", function(){
201
+ jQuery(function($){
202
+
203
+ const w = $(window).width();
204
+
205
+ const bh01 = parseInt($(".list01 dl").innerHeight());
206
+
207
+ const bh02 = parseInt($(".list02 dl").innerHeight());
208
+
209
+ const vw01 = (bh01 / w)*100;
210
+
211
+ const vw02 = (bh02 / w)*100;
212
+
213
+
214
+
215
+ const oh01 = parseInt($("#wrap .option_wrap:nth-of-type(2)").css('top'));
216
+
217
+ const oh02 = parseInt($("#wrap .option_wrap:nth-of-type(3)").css('top'));
218
+
219
+
220
+
221
+ const ov01 = (oh01 / w)*100;
222
+
223
+ const ov02 = (oh02 / w)*100;
224
+
225
+
226
+
227
+ const f01 = vw01 + ov01;
228
+
229
+ const f02 = vw01 + ov02;
230
+
231
+ const s01 = vw02 + ov01;
232
+
233
+ const s02 = vw02 + ov02;
234
+
235
+
236
+
237
+ $('.list01 dl').css('display','none');
238
+
239
+ $('.list02 dl').css('display','none');
240
+
241
+ $(".list01 p.btn").on("click", function(){
82
242
 
83
243
  if ($(this).hasClass('active01')) {
84
244
 
85
245
  // 開いている状態
86
246
 
247
+ $('.list02 dl').slideUp();
248
+
249
+ $('.list02 p').removeClass('active02');
250
+
87
251
  $(this).removeClass('active01').next().slideToggle();
88
252
 
89
- $('#customItemWrap #itemBtn .option select:nth-of-type(1)').animate({'top': OptionNthVw01 + 'vw'});
253
+ $('#wrap .option_wrap:nth-of-type(2)').animate({'top': ov01 + 'vw'});
90
-
254
+
91
- $('#customItemWrap #itemBtn .option select:nth-of-type(2)').animate({'top': OptionNthVw02 + 'vw'});
255
+ $('#wrap .option_wrap:nth-of-type(3)').animate({'top': ov02 + 'vw'});
92
-
93
- $('#customItemWrap #itemBtn .option select:nth-of-type(3)').animate({'top': OptionNthVw03 + 'vw'});
94
-
95
- $('#headDescription #M_nameInput1').animate({'top': InputNthVw01 + 'vw'});
96
-
97
- $('p.arrow02').animate({'top': ArrowNthVw02 + 'vw'});
98
256
 
99
257
  } else{
100
258
 
101
259
  // 閉じている状態
102
260
 
103
- $('p.tit_pat01 dl').not($('dl').slideUp());
261
+ $('.btn_list.list02 dl').slideUp();
262
+
263
+ $('.list02 p').removeClass('active02');
104
264
 
105
265
  $(this).addClass('active01').next().slideToggle();
106
266
 
107
- $('#customItemWrap #itemBtn .option select:nth-of-type(1)').animate({'top': f_VwTotal01 + 'vw'});
267
+ $('#wrap .option_wrap:nth-of-type(2)').animate({'top': f01 + 'vw'});
108
-
268
+
109
- $('#customItemWrap #itemBtn .option select:nth-of-type(2)').animate({'top': f_VwTotal02 + 'vw'});
269
+ $('#wrap .option_wrap:nth-of-type(3)').animate({'top': f02 + 'vw'});
110
-
111
- $('#customItemWrap #itemBtn .option select:nth-of-type(3)').animate({'top': f_VwTotal03 + 'vw'});
112
-
113
- $('#headDescription #M_nameInput1').animate({'top': f_InputTotal01 + 'vw'});
114
-
115
- $('p.arrow02').animate({'top': f_ArrowTotal02 + 'vw'});
116
270
 
117
271
  }
118
272
 
@@ -120,41 +274,35 @@
120
274
 
121
275
 
122
276
 
123
- $("p.tit_pat02").on("click", function(){
277
+ $(".list02 .btn").on("click", function(){
124
278
 
125
279
  if ($(this).hasClass('active02')) {
126
280
 
127
281
  // 開いている状態
128
282
 
283
+ $('.btn_list.list01 dl').slideUp();
284
+
285
+ $('.list01 p').removeClass('active01');
286
+
129
287
  $(this).removeClass('active02').next().slideToggle();
130
288
 
131
- $('#customItemWrap #itemBtn .option select:nth-of-type(2)').animate({'top': OptionNthVw02 + 'vw'});
289
+ $('#wrap .option_wrap:nth-of-type(3)').animate({'top': ov02 + 'vw'});
132
-
133
- $('#customItemWrap #itemBtn .option select:nth-of-type(3)').animate({'top': OptionNthVw03 + 'vw'});
290
+
134
-
135
- $('#customItemWrap #itemBtn .option select:nth-of-type(1)').animate({'top': OptionNthVw01 + 'vw'});
291
+ $('#wrap .option_wrap:nth-of-type(2)').animate({'top': ov01 + 'vw'});
136
-
137
- $('#headDescription #M_nameInput1').animate({'top': InputNthVw01 + 'vw'});
138
-
139
- $('p.arrow02').animate({'top': ArrowNthVw02 + 'vw'});
140
292
 
141
293
  } else{
142
294
 
143
295
  // 閉じている状態
144
296
 
145
- $('p.tit_pat02 dl').not($('dl').slideUp());
297
+ $('.btn_list.list01 dl').slideUp();
298
+
299
+ $('.list01 p').removeClass('active01');
146
300
 
147
301
  $(this).addClass('active02').next().slideToggle();
148
302
 
149
- $('#customItemWrap #itemBtn .option select:nth-of-type(2)').animate({'top': s_VwTotal02 + 'vw'});
303
+ $('#wrap .option_wrap:nth-of-type(3)').animate({'top': s02 + 'vw'});
150
-
304
+
151
- $('#customItemWrap #itemBtn .option select:nth-of-type(3)').animate({'top': s_VwTotal03 + 'vw'});
305
+ $('#wrap .option_wrap:nth-of-type(2)').animate({'top': s01 + 'vw'});
152
-
153
- $('#customItemWrap #itemBtn .option select:nth-of-type(1)').animate({'top': OptionNthVw01 + 'vw'});
154
-
155
- $('#headDescription #M_nameInput1').animate({'top': InputNthVw01 + 'vw'});
156
-
157
- $('p.arrow02').animate({'top': ArrowNthVw02 + 'vw'});
158
306
 
159
307
  }
160
308
 

2

質問の変更

2019/05/09 04:15

投稿

kakeru99
kakeru99

スコア17

test CHANGED
@@ -1 +1 @@
1
- アコーディオンで開いている状態で別のボタンした際の挙動につ
1
+ スクリプト早く処理て簡素化したい
test CHANGED
@@ -1,92 +1,14 @@
1
1
  ### 解決したいこと
2
2
 
3
- マホレスポンシブ。selectはすべてabsoluteでtopからの高さをvw指定。vw計算は問題な
3
+ クリプト自体動くのでがここからもっとシンプルに早く処理できるように書きたいのですがどように書けばもっと簡素化できるでょうか?
4
4
 
5
- アコーディオの高さ分dlにCSS付与たいと思っています。
5
+ また簡素化できるポイ見つけるコツなどはありますでしょうか?
6
-
7
- アコーディオンが開いている状態で別のボタンを押した際に高さがずれてしまう。
8
6
 
9
7
 
10
8
 
11
- ```html
12
-
13
- <div class="list01">
14
-
15
- <p class="tit01">アコーディオンボタン</p>
16
-
17
- <dl>
9
+ 宜しくおねがいします。
18
-
19
- <dt>あああ</dt>
20
-
21
- <dd>テキストテキスト</dd>
22
-
23
- <dd>テキストテキスト</dd>
24
-
25
- <dd>テキストテキスト</dd>
26
-
27
- </dl>
28
-
29
- </div>
30
10
 
31
11
 
32
-
33
- <div class="list02">
34
-
35
- <p class="tit02">アコーディオンボタン</p>
36
-
37
- <dl>
38
-
39
- <dt>あああ</dt>
40
-
41
- <dd>テキストテキスト</dd>
42
-
43
- <dd>テキストテキスト</dd>
44
-
45
- <dd>テキストテキスト</dd>
46
-
47
- </dl>
48
-
49
- </div>
50
-
51
-
52
-
53
- <div className="option_wrap">
54
-
55
- <select><option value="01"></option></select>
56
-
57
- <select><option value="02"></option></select>
58
-
59
- <select><option value="03"></option></select>
60
-
61
- </div>
62
-
63
- ```
64
-
65
-
66
-
67
- ```css
68
-
69
- .option_wrap select:nth-of-type(1){
70
-
71
- top: 287vw;
72
-
73
- }
74
-
75
- .option_wrap select:nth-of-type(2){
76
-
77
- top: 390vw;
78
-
79
- }
80
-
81
- .option_wrap select:nth-of-type(3){
82
-
83
- top: 500vw;
84
-
85
- }
86
-
87
-
88
-
89
- ```
90
12
 
91
13
  ```javascript
92
14
 
@@ -242,6 +164,4 @@
242
164
 
243
165
  </script>
244
166
 
245
- コード
246
-
247
167
  ```

1

見出しの修正

2019/04/26 08:55

投稿

kakeru99
kakeru99

スコア17

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ### 実現自体こと
1
+ ### 解決したいこと
2
2
 
3
3
  スマホレスポンシブ。selectはすべてabsoluteでtopからの高さをvwで指定。vwの計算は問題なし。
4
4