728x90
반응형
기존 height값에서 버튼 클릭시 자동으로 높이값을 주려고
height: auto;로 준 뒤 transition으로 애니메이션 효과를 주려고했는데
실행이 안되서 구글링을 하다가 발견한 스크립트이다.
html
<div class="tab-wrap">
<a href="#" class="tab">tab_01</a>
<div class="tab-contents">
<p>내용</p>
</div>
</div>
script
$('.tab').on('click', function(){
var el = $('.tab-contents'),
curHeight = el.height(), // 현재 정해져 있는 높이 값
autoHeight = el.css('height', 'auto').height(); // 원래 가지고 있는 높이 값
if(조건){
el.height(curHeight).animate({height: autoHeight}, 500);
} else{
el.animate({height: 0}, 500);
}
});
출처: https://kcmschool.com/104 [web sprit]
728x90
반응형
'실전 코딩 > javascript · jquery' 카테고리의 다른 글
버튼 따라다니는 bar 만들기(javascript) (0) | 2023.02.09 |
---|---|
스크롤 업/다운 이벤트 (scroll up/down event) (0) | 2022.05.08 |
게시판과 페이지네이션까지 구현해보기 (0) | 2022.02.12 |
url을 가져와서 이벤트 적용하기 (0) | 2021.09.06 |
width, innerWidth, outerWidth의 차이점 (0) | 2021.09.06 |
댓글