admin管理员组文章数量:1289857
I want to remove the transition and the delay of the Bootstrap 4 Collapse element. I'm using CSS to remove the transition itself:
.collapsing {
-webkit-transition: none;
transition: none;
display: none;
}
#collapseExample {background: red;}
That part works fine. But there is still some delay before the Collapse element shows. Is there any way to remove that?
Here's the HTML:
Navbar
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</form>
</div>
</nav>
<div class="collapse" id="collapseExample">
<div class="container">
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>
I want to remove the transition and the delay of the Bootstrap 4 Collapse element. I'm using CSS to remove the transition itself:
.collapsing {
-webkit-transition: none;
transition: none;
display: none;
}
#collapseExample {background: red;}
That part works fine. But there is still some delay before the Collapse element shows. Is there any way to remove that?
Here's the HTML:
Navbar
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</form>
</div>
</nav>
<div class="collapse" id="collapseExample">
<div class="container">
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>
Share
Improve this question
edited Apr 18, 2018 at 14:05
Cray
asked Apr 18, 2018 at 12:34
CrayCray
5,50313 gold badges91 silver badges195 bronze badges
2
- 1 have you try .collapsing { transition: none !important; } – HTML CSS Hupp Technologies Commented Apr 18, 2018 at 12:44
- yes, doesn't work :-/ – Cray Commented Apr 18, 2018 at 12:48
2 Answers
Reset to default 6You're applying a transition on the 'collapsing' class, which is added after the transition begins, and removed when it's ending. Instead of placing the override on this class, place it on the actual element, or the main class which doesn't gets changed.
From the documentation:
Usage The collapse plugin utilizes a few classes to handle the heavy lifting:
.collapse
hides the content
.collapse.show
shows the content
.collapsing
is added when the transition starts, and removed when it finishesThese classes can be found in _transitions.scss.
Simply add the following line to your CSS:
#collapseExample {transition: none; background: red;}
Link to docs
if you want to keep animation you can use and this is case when u have color on navbar
.navbar {
transition: ease-in .3s;
}
本文标签: javascriptRemove transition and delay of Bootstrap 4 Collapse elementStack Overflow
版权声明:本文标题:javascript - Remove transition and delay of Bootstrap 4 Collapse element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741425927a2378077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论