アコーディオンメニューのコードについて、質問させてください。
アコーディオンを実装するところまでは出来たのですが、クリックすると、flexで並んでいる横のアコーディオンメニューまで開いてしまいます。
クリックした箇所だけを、slideToggleで開きたいのですが、解決できていません。
また、アコーディオンの開閉に伴って「+」も動いてしまいます・・・
html、scss、jqueryのどこが悪いのか分かりませんので、教えて下さい。
html
1 <div class="faxg-flex"> 2 <div class="faq-group"> 3 <ul class="faq-ul"> 4 質問です 5 <span class="plus"></span> 6 </ul> 7 <li class="faq-li"> 8 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 9 10 </li> 11 </div> 12 13 14 <div class="faq-group"> 15 <ul class="faq-ul"> 16 質問です 17 <span class="plus"></span> 18 </ul> 19 <li class="faq-li"> 20 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 21 22 </li> 23 </div> 24 25 26 <div class="faq-group"> 27 <ul class="faq-ul"> 28 質問です 29 <span class="plus"></span> 30 </ul> 31 <li class="faq-li"> 32 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 33 34 </li> 35 </div> 36 37 38 <div class="faq-group"> 39 <ul class="faq-ul"> 40 質問です 41 <span class="plus"></span> 42 </ul> 43 <li class="faq-li"> 44 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 45 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 46 47 </li> 48 </div> 49 50 51 <div class="faq-group"> 52 <ul class="faq-ul"> 53 質問です 54 <span class="plus"></span> 55 </ul> 56 <li class="faq-li"> 57 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 58 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 59 この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。この文章はダミーです。文字の大きさ、量、字間、行間等を確認するために入れています。 60 61 </li> 62 </div> 63 64 </div>
scss
1 2 3.faq-group { 4 width: 48.1525%; 5 border-bottom: 1px solid #000; 6 padding-bottom: 25px; 7 position: relative; 8 9 &:nth-child(even) { 10 margin-left: 36px; 11 12 @include mq(sp) { 13 margin: 0 auto; 14 } 15 } 16 17 @include mq(sp) { 18 width: 100%; 19 } 20} 21 22.faq-ul { 23 font-size: 18px; 24 line-height: calc(26.06/18); 25 font-weight: 500; 26 padding-top: 30px; 27 cursor: pointer; 28 29 &::before { 30 content: "Q"; 31 padding-right: 24px; 32 padding-left: 16px; 33 34 @include mq(sp) { 35 color: #998866; 36 } 37 } 38 39 @include mq(sp) { 40 font-size: 14px; 41 line-height: calc(20.27/14); 42 padding-left: 3.8em; 43 text-indent: -3.8em; 44 } 45} 46 47.faq-li { 48 font-size: 18px; 49 line-height: calc(26.06/18); 50 font-weight: 500; 51 padding-left: 56px; 52 padding-top: 16px; 53 padding-bottom: 16px; 54 list-style: none; 55 text-decoration: none; 56 padding-right: 32px; 57 58 @include mq(sp) { 59 font-size: 14px; 60 line-height: calc(20.27/14); 61 } 62} 63 64.plus { 65 position: absolute; 66 top: 50%; 67 right: 8%; 68 69 &::before { 70 content: ""; 71 border: 1px solid; 72 width: 16px; 73 position: absolute; 74 // top: 50%; 75 // right: -200px; 76 transition: all 0.5s; 77 78 @include mq(sp) { 79 color: #998866; 80 } 81 82 } 83 84 &::after { 85 position: absolute; 86 content: ""; 87 border: 1px solid; 88 width: 16px; 89 transform: rotate(90deg); 90 // top: 50%; 91 // right: -200px; 92 transition: all 0.5s; 93 94 @include mq(sp) { 95 color: #998866; 96 } 97 98 } 99} 100 101 102.plus.open { 103 104 105 106 &::before { 107 transform: rotate(45deg); 108 transition: all 0.5s; 109 } 110 111 &::after { 112 transform: rotate(135deg); 113 transition: all 0.5s; 114 } 115} 116 117 118.faxg-flex { 119 display: flex; 120 flex-wrap: wrap; 121 122 @include mq(sp) { 123 display: block; 124 } 125}
jquery
1 2$(function () { 3 $('.faq-li').css("display", "none"); 4 $('.faq-ul').on('click', function () { 5 $(this).next().slideToggle(); 6 $(this).children('.plus').toggleClass('open'); 7 }) 8});

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。