Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Spoiler - Collapsable panel"
Bootstrap 3.2.0 Snippet by
ASDAFF
3.2.0
jQuery
Preview
HTML
CSS
JS
View Full Screen
Forked from
Fork
Fork this
Parent
1.0K
 
0 Fav
Post to Facebook
Tweet this
<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> </div> </div> <div class="col-md-6"> <div class="panel panel-info autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Information Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> <div class="panel panel-danger autocollapse"> <div class="panel-heading clickable"> <h3 class="panel-title"> Danger Title </h3> </div> <div class="panel-body"> <div class="alert alert-danger" role="alert">SPOILER ALERT!</div> </div> </div> </div> </div> </div> </div> </div>
.clickable { cursor: pointer; }
$(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); });
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76