Bootstrap 4.5 animates Collapse on page open when initial state is shown

Viewed 90

Prerequisites:

Bootstrap 4.5, Collapse initiated via JS API in default state "shown". https://jsfiddle.net/keeema/wa38qp2n/3/

<p>
  <button class="btn btn-primary" type="button" >
    Button with data-target
  </button>
</p>
<div class="collapse" id="collapseExample">
  <div class="card card-body">
    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
  </div>
</div>
$("#collapseExample").collapse({ toggle: true })

Actual behavior:

Bootstraps runs animation for showing Collapse when the page is opened.

Expected behavior:

Collapse content is shown immediately when the page is opened and without any animation.

Please, does anyone have any idea on how to fix this?

Thanks.

1 Answers

Add this

$('#collapseExample').addClass('no-transition').collapse('toggle')

With

.no-transition {
    transition: none !important;
}

$("#collapseExample").collapse({
  toggle: true
})

$('#collapseExample').addClass('no-transition').collapse('toggle')
.no-transition {
  transition: none !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

<p>
  <button class="btn btn-primary" type="button">
    Button with data-target
  </button>
</p>
<div class="collapse" id="collapseExample">
  <div class="card card-body">
    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
  </div>
</div>

Source : https://github.com/twbs/bootstrap/issues/18127

https://jsfiddle.net/275bpq8m/

Related