materializeCSS collapsible active change icon.

房东的猫 提交于 2019-12-05 06:21:42

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);
}
The Heavy Rhino

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);
}

The above two solutions still flip other icons in the collapsible header the other way round. The perfect solution will be to add a class to the icon.

<div class="collapsible-header">
<i class="material-icons vertical-align">filter_drama</i>
Header 1
<i class="material-icons right expand">expand_less</i>
</div>

Notice that a "expand" class is created. CSS would be similar to the above two, just that "expand" will be created

.collapsible-header.active i.expand {
    -ms-transform: rotate(180deg); /* IE 9 */
    -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
    transform: rotate(180deg);
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!