Bootstrap Accordion插件
2018-03-01 11:39 更新
折叠(collapse)插件也称为Web上的“Accordion”(手风琴)插件。
Accordion拥有多个垂直堆叠的标签,但一次只能打开一个标签。
在Bootstrap中,通过将多个面板组件一起容纳在单个容器中来创建Accordion。
面板有两个部分:panel-heading和panel-body。
要创建折叠,我们需要一组包含在容器内的面板。
此容器是使用具有类 panel-group
的div元素创建的。它还应该具有与其相关联的ID。
<div class="panel-group" id="accordion"></div>
例子
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body style="margin:30px">
<div class="panel-group" id="accordion">
<!-- Panel 1 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
Lorem ipsum dolor sit amet, consectetur ...
</div>
</div>
</div>
<!-- Panel 2 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Lorem ipsum dolor sit amet, consectetur ...
</div>
</div>
</div>
<!-- Panel 3 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion"
href="#collapseThree">
Collapsible Group Item #3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Lorem ipsum dolor sit amet, consectetur ...
</div>
</div>
</div>
</div>
</body>
</html>
以上内容是否对您有帮助:
更多建议: