부트 스트랩 축소 애니메이션이 부드럽 지 않음
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group">
<a for="collapseOne" data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne" class="btn btn-primary">+ addInfo </a>
<textarea class="form-control collapse" id="collapseOne" rows="4"></textarea>
</div>
<div class="form-group">
<a for="collapseTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="true" aria-controls="collapseOne" class="btn btn-info">+ subtitle </a>
<input type="text" class="form-control collapse" id="collapseTwo">
</div>
문제는 addInfo
탭을 클릭 할 때 를 확장 할 때 점프를 찾을 수 있다는 것입니다. text_area
즉, 애니메이션이 부드럽 지 않습니다.
내가 방금 가진 것처럼 다른 사람 이이 문제를 겪는 경우 대답은 축소하려는 콘텐츠를 a 안에 감싸고 div
콘텐츠 자체가 아닌 래퍼 div를 축소하는 것입니다.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group">
<a for="collapseOne" data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne" class="btn btn-primary">+ addInfo</a>
<div id="collapseOne" class="collapse">
<textarea class="form-control" rows="4"></textarea>
</div>
</div>
<div class="form-group">
<a for="collapseTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="true" aria-controls="collapseOne" class="btn btn-info">+ subtitle</a>
<input type="text" class="form-control collapse" id="collapseTwo">
</div>
부모 div ".collapse" 에 패딩이 있을 때 저킹이 발생합니다 .
패딩은 부모가 아닌 자식 div에 적용됩니다. jQuery는 패딩이 아닌 높이에 애니메이션을 적용합니다.
예:
<div class="form-group">
<a for="collapseOne" data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">+ addInfo</a>
<div class="collapse" id="collapseOne" style="padding: 0;">
<textarea class="form-control" rows="4" style="padding: 20px;"></textarea>
</div>
</div>
<div class="form-group">
<a for="collapseTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="true" aria-controls="collapseOne">+ subtitle</a>
<input type="text" class="form-control collapse" id="collapseTwo">
</div>
도움이 되었기를 바랍니다.
@CR Rollyson 답변에 추가,
In case if you have a collapsible div which has a min-height attribute, it will also cause the jerking. Try removing that attribute from directly collapsible div. Use it in the child div of the collapsible div.
<div class="form-group">
<a for="collapseOne" data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">+ Not Jerky</a>
<div class="collapse" id="collapseOne" style="padding: 0;">
<textarea class="form-control" rows="4" style="padding: 20px;">No padding on animated element. Padding on child.</textarea>
</div>
</div>
I think there can be several situations that cause the jerking. In my example, the issue deals with bottom margin on the non-animated child (even though the animated parent has no margin / padding). When removing the margin, the animation becomes smooth.
<div class="form-group">
<a for="collapseJerky" data-toggle="collapse" href="#collapseJerky" aria-expanded="true" aria-controls="collapseJerky">+ Jerky</a>
<div class="collapse" id="collapseJerky" style="margin:0; padding: 0;">
<textarea class="form-control" rows="4" style="margin-bottom: 20px;">No margin or padding on animated element. Margin on child.</textarea>
</div>
</div>
<div class="form-group">
<a data-toggle="collapse" href="#collapseNotJerky" aria-expanded="true" aria-controls="collapseNotJerky">+ Not Jerky</a>
<div class="collapse" id="collapseNotJerky" style="margin:0 padding: 0;">
<textarea class="form-control" rows="4" style="margin-bottom: 0;">No margin or padding on animated element or on child.</textarea>
</div>
</div>
<p>
Moles and trolls, moles and trolls, work, work, work, work, work. We never see the light of day. This is just content below the "Not Jerky" to show that the animation is smooth.
</p>
Mine got smoother not by wrapping each child but wrapping whole markup with a helper div. Like this:
<div class="accordeonBigWrapper">
<div class="panel-group accordion partnersAccordeonWrapper" id="partnersAccordeon" role="tablist" aria-multiselectable="false">
accordeon markup inside...
</div>
</div>
Do not set a height on the .collapse
tag. It affects the animation, if the height is overridden with css; it will not animate correctly.
Although this has been answer https://stackoverflow.com/a/28375912/5413283, and regarding padding it is not mentioned in the original answer but here https://stackoverflow.com/a/33697157/5413283.
i am just adding here for visual presentation and a cleaner code.
Tested on Bootstrap 4 ✓
Create a new parent div and add the bootstrap collapse. Remove the classes from the textarea
<div class="collapse" id="collapseOne"> <!-- bootstrap class on parent -->
<textarea class="form-control" rows="4"></textarea>
</div> <!-- // bootstrap class on parent -->
If you want to have spaces around, wrap textarea
with padding. Do not add margin
, it has the same issue.
<div class="collapse" id="collapseOne"> <!-- bootstrap class on parent -->
<div class="py-4"> <!-- padding for textarea -->
<textarea class="form-control" rows="4"></textarea>
</div> <!-- // padding for textarea -->
</div> <!-- // bootstrap class on parent -->
Tested on Bootstrap 3 ✓
Same as bootstrap 4. Wrap the textare
with collapse
class.
<div class="collapse" id="collapseOne"> <!-- bootstrap class on parent -->
<textarea class="form-control" rows="4"></textarea>
</div> <!-- // bootstrap class on parent -->
And for padding
Bootstrap 3 does not have p-* classes like Bootstrap 4 . So you need to create your own. Do not use padding
it will not work, use margin
.
#collapseOne textarea {
margin: 10px 0 10px 0;
}
ReferenceURL : https://stackoverflow.com/questions/27221332/bootstrap-collapse-animation-not-smooth
'programing' 카테고리의 다른 글
C를 사용하여 Linux에서 CPU 수를 얻는 방법은 무엇입니까? (0) | 2021.01.10 |
---|---|
Ruby에서 외부주기를 끊는 방법은 무엇입니까? (0) | 2021.01.09 |
Windows에 Aptana Studio 3.6을 설치할 수 없습니다. (0) | 2021.01.09 |
MySQL에서 정수 시퀀스 생성 (0) | 2021.01.09 |
iPhone 설정에 설정 번들이 표시되지 않음 (0) | 2021.01.09 |