Auto-close Bootstrap accordion panel when switch to mobile screen size -


using bootstrap 2.3.2 have accordion single panel open when page loaded.

          <div class="accordion" id="refine">               <div class="accordion-heading">                 <a class="accordion-toggle" data-toggle="collapse" data-parent="#refine" href="#refine-search">                   title                 </a>               </div>               <div id="refine-search" class="accordion-body collapse in">                 <div class="accordion-inner">                   test text....                 </div>               </div>           </div>                     

the site responsive. when switching mobile screen size [ @media (max-width: 979px) ] want accordion panel close automatically, i.e. want div refine-search line change "collapse out".

when in mobile mode, accordion must still work, e.g. user can click on accordion heading , panel expand hence not want duplicate divs turn panel off using .hidden-desktop utility classes etc.

i've searched high , low answer - can help?

so figured out how this, posting in case it's of anyone.

alter html to:

<div class="accordion" id="refine">      <div class="hidden-phone">         <div class="accordion-heading">             <a class="accordion-toggle" data-toggle="collapse" data-parent="#refine" href="#refine-search">                 <legend>                     <h2>refine search</h2></legend>             </a>         </div>     </div>      <div class="visible-phone">         <div class="accordion-heading">             <a class="accordion-toggle" data-toggle="collapse" data-parent="#refine" href="#refine-search">                 <legend>                     <h2>refine search (press reveal)</h2></legend>             </a>         </div>     </div>      <div id="refine-search" class="accordion-body collapse in">          <div class="accordion-inner">              test text....         </div>      </div>  </div> 

and use js in file.

$(window).bind('resize load', function() {     if ($(this).width() < 767) {         $('#refine-search').removeclass('in');         $('#refine-search').addclass('out');     } else {         $('#refine-search').removeclass('out');         $('#refine-search').addclass('in');     } }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -