Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

materializeCSS collapsible active change icon.

I am looking for some help with collapsible I am trying to change the icon on the headers when they are active but cant seem to solve the problem of if I click on another header without closing the first one having the proper icon being displayed.

Here is a codepen with an example of my issue. http://codepen.io/FPC/pen/xZEWVY

here is my code:

<div class="container">
  <div class="row">
    <div class="col s6">
      <ul class="collapsible popout" data-collapsible="accordion">
        <li>
          <div class="collapsible-header">
            <i class="material-icons right more">expand_more</i>
            <i class="material-icons right less" style="display: none">expand_less</i>
            Article Title
          </div>
          <div class="collapsible-body">
            <p>
              Content Snipit        
            </p>
          </div>
        </li>
        <li>
          <div class="collapsible-header">
            <i class="material-icons right more">expand_more</i>
            <i class="material-icons right less" style="display: none">expand_less</i>
            Article Title
          </div>
          <div class="collapsible-body">
            <p>
              Content Snipit
            </p>
          </div>
        </li>
        <li>
          <div class="collapsible-header">
            <i class="material-icons right more">expand_more</i>
            <i class="material-icons right less" style="display: none">expand_less</i>
            Article Title
          </div>
          <div class="collapsible-body">
            <p>
              Content Snipit
            </p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</div>

here is the JS I am using

    $(document).ready(function(){
  $( ".collapsible-header" ).click(function() {
      $(".more",this).toggle()
      $(".less", this).toggle()
  });
});
like image 223
FPcond Avatar asked Dec 26 '15 14:12

FPcond


2 Answers

You don't need the use javascript for this

delete javascript and use only css

html

<ul class="collapsible" data-collapsible="accordion">
  <li>
      <div class="collapsible-header">
       <i class="material-icons">expand_less</i>First</div>
   </li>
   <li>
      <div class="collapsible-header">
       <i class="material-icons">expand_less</i>Second</div>
   </li>
</ul>

css

  .collapsible li.active i {
  -ms-transform: rotate(180deg); /* IE 9 */
  -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
  transform: rotate(180deg);
}
like image 80
Hakan Avatar answered Nov 06 '22 02:11

Hakan


As an addition to Hakan's answer, You can use the collapsible-header class to avoid changing other icons within the collapsible class (accordion content). The CSS code that worked for me is:

CSS

.collapsible-header.active i {
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
like image 35
The Heavy Rhino Avatar answered Nov 06 '22 03:11

The Heavy Rhino