차근차근/부트스트랩

메뉴 토글 -collapse2

예쁜꽃이피었으면 2022. 3. 23. 11:37

https://action713.tistory.com/entry/%EB%A9%94%EB%89%B4-%ED%86%A0%EA%B8%80-collapse

 

메뉴 토글 -collapse

http://bootstrapk.com/javascript/#collapse 자바스크립트 · 부트스트랩 Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mus..

action713.tistory.com

위의 링크처럼 만들었는데 

나는 메뉴에 적용한 것이기 때문에 1차에 적용된 콜랩스가..? 하위메뉴로 들어가도 그대로 유지되어야 했다.

그래서 적용해본게 아코디언이었다

https://getbootstrap.kr/docs/5.1/components/accordion/

더보기
<div class="accordion" id="accordionExample">
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
      <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
        Accordion Item #1
      </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingTwo">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
        Accordion Item #2
      </button>
    </h2>
    <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingThree">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
        Accordion Item #3
      </button>
    </h2>
    <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
</div>

그치만 내 화면에서는 적용되지 않았는데.. 내가 쓰고있는 부트스트랩의 버전은 4.5였기 때문에 5.1버전의 아코디언 클래스를 사용할 수 없었고.

https://getbootstrap.com/docs/4.5/components/collapse/#accordion-example

4.5 버전의 아코디언을 찾아서 적용했다.

더보기
<div class="accordion" id="accordionExample">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h2 class="mb-0">
        <button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Collapsible Group Item #1
        </button>
      </h2>
    </div>

    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingTwo">
      <h2 class="mb-0">
        <button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Collapsible Group Item #2
        </button>
      </h2>
    </div>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingThree">
      <h2 class="mb-0">
        <button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Collapsible Group Item #3
        </button>
      </h2>
    </div>
    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>

카드 클래스를 사용한 버전이었고

카드의 색깔은

https://getbootstrap.com/docs/4.5/components/card/

https://getbootstrap.com/docs/4.5/utilities/colors/

여기서 보고 변경했다.

 

아코디언메뉴까지는 됐고.. 이제 하위메뉴로 이동해도 

1차 메뉴가 열려있어야 한다.. 또 찾아보자................'-'

 

 


이거... 기능이 있을 줄 알았는데..보이질 않았다.. 못 찾은건가

 

많은 방법이 있겠지만.. 그냥 이렇게 했다.

...
<script>
$(document).read(function(){
	var menuid = sessionStorage.getItem("sessionMenuId");
    if(menuid != null){
    	var menuarr = ['One','Two','Three','Four'];
        for(var i=0; i < menuarr.length; i++){
        	var menu = '#'+'collapse'+menuarr[i];
            if(menuarr[i] === menuid){
            	$(menu).addClass("show");
            }else{
            	$(menu).removeClass("show");
            }
        }
    }else{
    	$('#collapseOne').addClass("show");
    }
});

function getDepth1(menu){
	sessionStorage.setItem("sesstionMenuId",menu);
}	
</script>

..
<h2 class="card-header" id="headingOne" onClick="getDepth1('One');">
..
<h2 class="card-header" id="headingTwo" onClick="getDepth1('Two');">
..
<h2 class="card-header" id="headingThree" onClick="getDepth1('Three');">
..
<h2 class="card-header" id="headingFour" onClick="getDepth1('Four');">
..

 

 

 

 

 

 

 

 

 

반응형

'차근차근 > 부트스트랩' 카테고리의 다른 글

부트스트랩 5.1 폰트 바꾸기  (0) 2023.02.02
가끔 404  (0) 2022.11.15
popover / icon  (0) 2022.10.19
부트스트랩 필요한 링크  (0) 2022.08.11
메뉴 토글 -collapse  (0) 2022.03.22