teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

javascriptとcssのインデントを直しました

2021/01/04 11:40

投稿

takawork
takawork

スコア95

title CHANGED
File without changes
body CHANGED
@@ -261,7 +261,6 @@
261
261
  switchAccordion,
262
262
  touchSupported = ('ontouchstart' in window),
263
263
  pointerSupported = ('pointerdown' in window);
264
-
265
264
  skipClickDelay = function(e){
266
265
  e.preventDefault();
267
266
  e.target.click();
@@ -273,17 +272,17 @@
273
272
  setAccordionAria = function(el1, el2, expanded){
274
273
  switch(expanded) {
275
274
  case "true":
276
- setAriaAttr(el1, 'aria-expanded', 'true');
275
+ setAriaAttr(el1, 'aria-expanded', 'true');
277
- setAriaAttr(el2, 'aria-hidden', 'false');
276
+ setAriaAttr(el2, 'aria-hidden', 'false');
278
- break;
277
+ break;
279
278
  case "false":
280
- setAriaAttr(el1, 'aria-expanded', 'false');
279
+ setAriaAttr(el1, 'aria-expanded', 'false');
281
- setAriaAttr(el2, 'aria-hidden', 'true');
280
+ setAriaAttr(el2, 'aria-hidden', 'true');
282
- break;
281
+ break;
283
282
  default:
284
- break;
283
+ break;
285
- }
284
+ }
286
- };
285
+ };
287
286
  //function
288
287
  switchAccordion = function(e) {
289
288
  console.log("triggered");
@@ -295,12 +294,11 @@
295
294
  } else {
296
295
  setAccordionAria(thisQuestion, thisAnswer, 'false');
297
296
  }
298
- thisQuestion.classList.toggle('is-collapsed');
297
+ thisQuestion.classList.toggle('is-collapsed');
299
- thisQuestion.classList.toggle('is-expanded');
298
+ thisQuestion.classList.toggle('is-expanded');
300
299
  thisAnswer.classList.toggle('is-collapsed');
301
300
  thisAnswer.classList.toggle('is-expanded');
302
-
303
- thisAnswer.classList.toggle('animateIn');
301
+ thisAnswer.classList.toggle('animateIn');
304
302
  };
305
303
  for (var i=0,len=accordionToggles.length; i<len; i++) {
306
304
  if(touchSupported) {

2

javascriptを追記

2021/01/04 11:39

投稿

takawork
takawork

スコア95

title CHANGED
File without changes
body CHANGED
@@ -253,74 +253,63 @@
253
253
  }
254
254
  ```
255
255
  ```
256
- jQuery(function () {
256
+ jQuery(function(){
257
+ var d = document,
258
+ accordionToggles = d.querySelectorAll('.js-accordionTrigger'),
259
+ setAria,
260
+ setAccordionAria,
261
+ switchAccordion,
262
+ touchSupported = ('ontouchstart' in window),
263
+ pointerSupported = ('pointerdown' in window);
264
+
265
+ skipClickDelay = function(e){
266
+ e.preventDefault();
257
- 'use strict';
267
+ e.target.click();
268
+ }
258
269
 
259
- document.addEventListener("touchstart", function () {}, false);
260
- jQuery(function () {
261
-
262
- jQuery('body').wrapInner('<div class="wsmenucontainer" />');
263
- jQuery('<div class="overlapblackbg"></div>').prependTo('.wsmenu');
264
-
265
- jQuery('#wsnavtoggle').click(function () {
266
- jQuery('body').toggleClass('wsactive');
267
- });
268
-
269
- jQuery('.overlapblackbg').click(function () {
270
- jQuery("body").removeClass('wsactive');
271
- });
272
-
273
- jQuery('.wsmenu > .wsmenu-list > li').has('.sub-menu').prepend('<span class="wsmenu-click"><i class="wsmenu-arrow"></i></span>');
274
- jQuery('.wsmenu > .wsmenu-list > li').has('.wsmegamenu').prepend('<span class="wsmenu-click"><i class="wsmenu-arrow"></i></span>');
275
-
276
- jQuery('.wsmenu-click').click(function () {
277
- jQuery(this).toggleClass('ws-activearrow')
278
- .parent().siblings().children().removeClass('ws-activearrow');
279
- jQuery(".wsmenu > .wsmenu-list > li > .sub-menu, .wsmegamenu").not(jQuery(this).siblings('.wsmenu > .wsmenu-list > li > .sub-menu, .wsmegamenu')).slideUp('slow');
280
- jQuery(this).siblings('.sub-menu').slideToggle('slow');
281
- jQuery(this).siblings('.wsmegamenu').slideToggle('slow');
282
- });
283
-
284
- jQuery('.wsmenu > .wsmenu-list > li > ul > li').has('.sub-menu').prepend('<span class="wsmenu-click02"><i class="wsmenu-arrow"></i></span>');
285
- jQuery('.wsmenu > .wsmenu-list > li > ul > li > ul > li').has('.sub-menu').prepend('<span class="wsmenu-click02"><i class="wsmenu-arrow"></i></span>');
286
-
287
- jQuery('.wsmenu-click02').click(function () {
288
- jQuery(this).children('.wsmenu-arrow').toggleClass('wsmenu-rotate');
289
- jQuery(this).siblings('li > .sub-menu').slideToggle('slow');
290
- });
291
-
292
- jQuery(window).on('resize', function () {
293
-
294
- if (jQuery(window).outerWidth() < 992) {
295
- jQuery('.wsmenu').css('height', jQuery(this).height() + "px");
296
- jQuery('.wsmenucontainer').css('min-width', jQuery(this).width() + "px");
297
- } else {
298
- jQuery('.wsmenu').removeAttr("style");
299
- jQuery('.wsmenucontainer').removeAttr("style");
300
- jQuery('body').removeClass("wsactive");
301
- jQuery('.wsmenu > .wsmenu-list > li > .wsmegamenu, .wsmenu > .wsmenu-list > li > ul.sub-menu, .wsmenu > .wsmenu-list > li > ul.sub-menu > li > ul.sub-menu, .wsmenu > .wsmenu-list > li > ul.sub-menu > li > ul.sub-menu > li > ul.sub-menu').removeAttr("style");
302
- jQuery('.wsmenu-click').removeClass("ws-activearrow");
303
- jQuery('.wsmenu-click02 > i').removeClass("wsmenu-rotate");
304
- }
305
-
306
- });
307
-
308
- jQuery(window).trigger('resize');
309
-
310
- });
311
-
312
- //Mobile Search Box
313
- jQuery(window).on("load", function () {
314
- jQuery('.wsmobileheader .wssearch').on("click", function () {
315
- jQuery(this).toggleClass("wsopensearch");
316
- });
317
- jQuery("body, .wsopensearch .wscloseicon").on("click", function () {
318
- jQuery(".wssearch").removeClass('wsopensearch');
319
- });
320
- jQuery(".wssearch, .wssearchform form").on("click", function (e) {
321
- e.stopPropagation();
322
- });
323
- });
324
-
325
- }());
270
+ setAriaAttr = function(el, ariaType, newProperty){
271
+ el.setAttribute(ariaType, newProperty);
272
+ };
273
+ setAccordionAria = function(el1, el2, expanded){
274
+ switch(expanded) {
275
+ case "true":
276
+ setAriaAttr(el1, 'aria-expanded', 'true');
277
+ setAriaAttr(el2, 'aria-hidden', 'false');
278
+ break;
279
+ case "false":
280
+ setAriaAttr(el1, 'aria-expanded', 'false');
281
+ setAriaAttr(el2, 'aria-hidden', 'true');
282
+ break;
283
+ default:
284
+ break;
285
+ }
286
+ };
287
+ //function
288
+ switchAccordion = function(e) {
289
+ console.log("triggered");
290
+ e.preventDefault();
291
+ var thisAnswer = e.target.parentNode.nextElementSibling;
292
+ var thisQuestion = e.target;
293
+ if(thisAnswer.classList.contains('is-collapsed')) {
294
+ setAccordionAria(thisQuestion, thisAnswer, 'true');
295
+ } else {
296
+ setAccordionAria(thisQuestion, thisAnswer, 'false');
297
+ }
298
+ thisQuestion.classList.toggle('is-collapsed');
299
+ thisQuestion.classList.toggle('is-expanded');
300
+ thisAnswer.classList.toggle('is-collapsed');
301
+ thisAnswer.classList.toggle('is-expanded');
302
+
303
+ thisAnswer.classList.toggle('animateIn');
304
+ };
305
+ for (var i=0,len=accordionToggles.length; i<len; i++) {
306
+ if(touchSupported) {
307
+ accordionToggles[i].addEventListener('touchstart', skipClickDelay, false);
308
+ }
309
+ if(pointerSupported){
310
+ accordionToggles[i].addEventListener('pointerdown', skipClickDelay, false);
311
+ }
312
+ accordionToggles[i].addEventListener('click', switchAccordion, false);
313
+ }
314
+ })();
326
315
  ```

1

コードを変更

2021/01/04 11:00

投稿

takawork
takawork

スコア95

title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,13 @@
11
11
  どうすれば直りますでしょうか?
12
12
 
13
13
  ```
14
+ <section class="question-content">
15
+ <div class="question-content-wrap">
16
+ <div class="question-content-wrap-ttl">
17
+ <h1>よくある質問(FAQ)</h1>
18
+ </div>
19
+ <div class="question-content-wrap-list">
14
- <div class="question-content-wrap-list-container">
20
+ <div class="question-content-wrap-list-container">
15
21
  <div class="accordion">
16
22
  <dl>
17
23
  <dt>
@@ -38,125 +44,212 @@
38
44
  </dl>
39
45
  </div>
40
46
  </div>
47
+ </div>
48
+ </div>
49
+ </section>
41
50
  ```
42
51
  ```
52
+ .question-content {
53
+ height: auto;
54
+ min-height: 600px;
55
+ background-color: white;
56
+ border: 1vw solid #5BCBAC;
57
+ padding-top: 30px;
58
+ }
59
+
60
+ .question-content-wrap {
61
+ max-width: 1080px;
62
+ margin: 0 auto;
63
+ }
64
+
65
+ .question-content-wrap-ttl {
66
+ text-align: center;
67
+ }
68
+
69
+ .question-content-wrap-ttl h1 {
70
+ font-weight: bold;
71
+ font-size: 42px;
72
+ margin-bottom: 0px;
73
+ }
74
+
43
75
  .accordion dl,
44
76
  .accordion-list {
45
- border:1px solid #ddd;
77
+ border: 1px solid #ddd;
46
- &:after {
47
- content: "";
48
- display:block;
49
- height:1em;
50
- width:100%;
51
- background-color:darken(#38cc70, 10%);
52
- }
53
78
  }
79
+
80
+ .accordion dl:after,
81
+ .accordion-list:after {
82
+ content: "";
83
+ display: block;
84
+ height: 1em;
85
+ width: 100%;
86
+ background-color: #2ba659;
87
+ }
88
+
54
89
  .accordion dd,
55
90
  .accordion__panel {
56
- background-color:#eee;
91
+ background-color: #eee;
57
- font-size:1em;
92
+ font-size: 1em;
58
- line-height:1.5em;
93
+ line-height: 1.5em;
59
94
  }
95
+
60
96
  .accordion p {
61
- padding:1em 2em 1em 2em;
97
+ padding: 1em 2em 1em 2em;
62
98
  }
63
99
 
64
100
  .accordion {
65
- position:relative;
101
+ position: relative;
66
- background-color:#eee;
102
+ background-color: #eee;
67
103
  }
104
+
68
105
  .question-content-wrap-list-container {
69
- max-width:960px;
106
+ max-width: 960px;
70
- margin:0 auto;
107
+ margin: 0 auto;
71
- padding:2em 0 2em 0;
108
+ padding: 2em 0 2em 0;
72
109
  }
110
+
73
111
  .accordionTitle,
74
112
  .accordion__Heading {
75
- background-color:#38cc70;
113
+ background-color: #38cc70;
76
- text-align:center;
114
+ text-align: center;
77
- font-weight:700;
115
+ font-weight: 700;
78
- padding:2em;
116
+ padding: 2em;
79
- display:block;
117
+ display: block;
80
- text-decoration:none;
118
+ text-decoration: none;
81
- color:#fff;
119
+ color: #fff;
120
+ -webkit-transition: background-color 0.5s ease-in-out;
82
- transition:background-color 0.5s ease-in-out;
121
+ transition: background-color 0.5s ease-in-out;
83
- border-bottom:1px solid darken(#38cc70, 5%);
122
+ border-bottom: 1px solid #30bb64;
84
- &:before {
85
- content: "+";
86
- font-size:2.5em;
87
- line-height:0.5em;
88
- float: right;
89
- transition: transform 0.3s ease-in-out;
90
- }
91
- &:hover {
92
- background-color:darken(#38cc70, 10%);
93
- }
94
- &:after {
95
- content: "Q";
96
- font-size:2.5em;
97
- line-height:0.5em;
98
- float: left;
99
- transition: transform 0.3s ease-in-out;
100
- }
101
123
  }
124
+
125
+ .accordionTitle:before,
126
+ .accordion__Heading:before {
127
+ content: "+";
128
+ font-size: 2.5em;
129
+ line-height: 0.5em;
130
+ float: right;
131
+ -webkit-transition: -webkit-transform 0.3s ease-in-out;
132
+ transition: -webkit-transform 0.3s ease-in-out;
133
+ transition: transform 0.3s ease-in-out;
134
+ transition: transform 0.3s ease-in-out, -webkit-transform 0.3s ease-in-out;
135
+ }
136
+
137
+ .accordionTitle:hover,
138
+ .accordion__Heading:hover {
139
+ background-color: #2ba659;
140
+ }
141
+
142
+ .accordionTitle:after,
143
+ .accordion__Heading:after {
144
+ content: "Q";
145
+ font-size: 2.5em;
146
+ line-height: 0.5em;
147
+ float: left;
148
+ -webkit-transition: -webkit-transform 0.3s ease-in-out;
149
+ transition: -webkit-transform 0.3s ease-in-out;
150
+ transition: transform 0.3s ease-in-out;
151
+ transition: transform 0.3s ease-in-out, -webkit-transform 0.3s ease-in-out;
152
+ }
153
+
102
- .accordionTitleActive,
154
+ .accordionTitleActive,
103
155
  .accordionTitle.is-expanded {
104
- background-color:darken(#38cc70, 10%);
156
+ background-color: #2ba659;
105
- &:before {
106
- transform:rotate(-225deg);
107
- }
108
157
  }
158
+
159
+ .accordionTitleActive:before,
160
+ .accordionTitle.is-expanded:before {
161
+ -webkit-transform: rotate(-225deg);
162
+ transform: rotate(-225deg);
163
+ }
164
+
109
165
  .accordionItem {
110
- height:auto;
166
+ height: auto;
111
- overflow:hidden;
167
+ overflow: hidden;
112
- //SHAME: magic number to allow the accordion to animate
113
-
114
- max-height:50em;
168
+ max-height: 50em;
169
+ -webkit-transition: max-height 1s;
115
- transition:max-height 1s;
170
+ transition: max-height 1s;
116
-
117
-
118
- @media screen and (min-width:48em) {
119
- max-height:15em;
120
- transition:max-height 0.5s
121
-
122
- }
123
-
124
-
125
171
  }
172
+
126
-
173
+ @media screen and (min-width: 48em) {
174
+ .accordionItem {
175
+ max-height: 15em;
176
+ -webkit-transition: max-height 0.5s;
177
+ transition: max-height 0.5s;
178
+ }
179
+ }
180
+
127
181
  .accordionItem.is-collapsed {
128
- max-height:0;
182
+ max-height: 0;
129
183
  }
184
+
130
185
  .no-js .accordionItem.is-collapsed {
131
186
  max-height: auto;
132
187
  }
188
+
133
189
  .animateIn {
190
+ -webkit-animation: accordionIn 0.45s normal ease-in-out both 1;
134
- animation: accordionIn 0.45s normal ease-in-out both 1;
191
+ animation: accordionIn 0.45s normal ease-in-out both 1;
135
192
  }
193
+
136
194
  .animateOut {
195
+ -webkit-animation: accordionOut 0.45s alternate ease-in-out both 1;
137
- animation: accordionOut 0.45s alternate ease-in-out both 1;
196
+ animation: accordionOut 0.45s alternate ease-in-out both 1;
138
197
  }
198
+
199
+ @-webkit-keyframes accordionIn {
200
+ 0% {
201
+ opacity: 0;
202
+ -webkit-transform: scale(0.9) rotateX(-60deg);
203
+ transform: scale(0.9) rotateX(-60deg);
204
+ -webkit-transform-origin: 50% 0;
205
+ transform-origin: 50% 0;
206
+ }
207
+ 100% {
208
+ opacity: 1;
209
+ -webkit-transform: scale(1);
210
+ transform: scale(1);
211
+ }
212
+ }
213
+
139
214
  @keyframes accordionIn {
140
215
  0% {
141
216
  opacity: 0;
217
+ -webkit-transform: scale(0.9) rotateX(-60deg);
142
- transform:scale(0.9) rotateX(-60deg);
218
+ transform: scale(0.9) rotateX(-60deg);
219
+ -webkit-transform-origin: 50% 0;
143
- transform-origin: 50% 0;
220
+ transform-origin: 50% 0;
144
221
  }
145
222
  100% {
146
- opacity:1;
223
+ opacity: 1;
224
+ -webkit-transform: scale(1);
147
- transform:scale(1);
225
+ transform: scale(1);
148
226
  }
149
227
  }
150
228
 
229
+ @-webkit-keyframes accordionOut {
230
+ 0% {
231
+ opacity: 1;
232
+ -webkit-transform: scale(1);
233
+ transform: scale(1);
234
+ }
235
+ 100% {
236
+ opacity: 0;
237
+ -webkit-transform: scale(0.9) rotateX(-60deg);
238
+ transform: scale(0.9) rotateX(-60deg);
239
+ }
240
+ }
241
+
151
242
  @keyframes accordionOut {
152
- 0% {
243
+ 0% {
153
- opacity: 1;
244
+ opacity: 1;
245
+ -webkit-transform: scale(1);
154
- transform:scale(1);
246
+ transform: scale(1);
155
- }
247
+ }
156
- 100% {
248
+ 100% {
157
- opacity:0;
249
+ opacity: 0;
250
+ -webkit-transform: scale(0.9) rotateX(-60deg);
158
- transform:scale(0.9) rotateX(-60deg);
251
+ transform: scale(0.9) rotateX(-60deg);
159
- }
252
+ }
160
253
  }
161
254
  ```
162
255
  ```