"Spoiler - Collapsable panel"
Bootstrap 3.2.0 Snippet by ASDAFF

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<h2>Spoiler - using panel</h2>
<h4>Use</h4>
<p>Use <code>autocollapse</code> class on main <code>panel</code> element to auto-close spoiler on page-load.</p>
<p>Use <code>clickable</code> class on <code>panel-heading</code> element to be able to collapse the panel.</p>
<h4>Examles</h4>
<div class="panel panel-primary">
<div class="panel-heading clickable">
<h3 class="panel-title">Primary Title</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div class="panel panel-success autocollapse">
<div class="panel-heading clickable">
<h3 class="panel-title">
Success Title
</h3>
</div>
<div class="panel-body">
<div class="alert alert-danger" role="alert">SPOILER ALERT!</div>
</div>
</div>
<div class="panel panel-warning autocollapse">
<div class="panel-heading clickable">
<h3 class="panel-title">
Warning Title
</h3>
</div>
<div class="panel-body">
<div class="alert alert-danger" role="alert">SPOILER ALERT!</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
.clickable
{
cursor: pointer;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$(document).on('click', '.panel div.clickable', function (e) {
var $this = $(this); //Heading
var $panel = $this.parent('.panel');
var $panel_body = $panel.children('.panel-body');
var $display = $panel_body.css('display');
if ($display == 'block') {
$panel_body.slideUp();
} else if($display == 'none') {
$panel_body.slideDown();
}
});
$(document).ready(function(e){
var $classy = '.panel.autocollapse';
var $found = $($classy);
$found.find('.panel-body').hide();
$found.removeClass($classy);
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: