jquery - Bootstrap 3 Collapse show state with Chevron icon -
using core example taken bootstrap 3 javascript examples page collapse, have been able show state of collapse using chevron icons.
i have working using:
$('#accordion .accordion-toggle').click(function (e) { var chevstate = $(e.target).siblings("i.indicator").toggleclass('glyphicon-chevron-down glyphicon-chevron-up'); $("i.indicator").not(chevstate).removeclass("glyphicon-chevron-down").addclass("glyphicon-chevron-up"); });
this works (not tested in browsers), i'm wondering if there's more elegant solution this?
ideally i'd use core function, i'm not sure how achieve same results it.
$('#accordion').on('hidden.bs.collapse', function () { //do something... })
here's working version in jsfiddle.
for following html (from bootstrap 3 examples):
<div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a class="accordion-toggle" 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"> anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. food truck quinoa nesciunt laborum eiusmod. brunch 3 wolf moon tempor, sunt aliqua put bird on squid single-origin coffee nulla assumenda shoreditch et. nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. ad vegan excepteur butcher vice lomo. leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt haven't heard of them accusamus labore sustainable vhs. </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a class="accordion-toggle" 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"> anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. food truck quinoa nesciunt laborum eiusmod. brunch 3 wolf moon tempor, sunt aliqua put bird on squid single-origin coffee nulla assumenda shoreditch et. nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. ad vegan excepteur butcher vice lomo. leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt haven't heard of them accusamus labore sustainable vhs. </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a class="accordion-toggle" 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"> anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. food truck quinoa nesciunt laborum eiusmod. brunch 3 wolf moon tempor, sunt aliqua put bird on squid single-origin coffee nulla assumenda shoreditch et. nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. ad vegan excepteur butcher vice lomo. leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt haven't heard of them accusamus labore sustainable vhs. </div> </div> </div> </div>
the following style work:
.panel-heading .accordion-toggle:after { /* symbol "opening" panels */ font-family: 'glyphicons halflings'; /* essential enabling glyphicon */ content: "\e114"; /* adjust needed, taken bootstrap.css */ float: right; /* adjust needed */ color: grey; /* adjust needed */ } .panel-heading .accordion-toggle.collapsed:after { /* symbol "collapsed" panels */ content: "\e080"; /* adjust needed, taken bootstrap.css */ }
visual effect:
Comments
Post a Comment