Twitter bootstrap 3.0 icon change on collapse

前端 未结 10 1209
长发绾君心
长发绾君心 2020-12-04 19:41

This is about Bootstrap 3.0. I would like the icon/glyphicon to change on collapse. I.e, from a closed folder to an open one.

I have searched far and wide, and have

10条回答
  •  [愿得一人]
    2020-12-04 20:06

    This code finds your accordion with the ID of 'Accordion'. When the shown event fires on the collapsed panel, the icon is found in the header panel (the previous element) and it finds and changes your glyph icon element within that HTML code block:

    $('#accordion .panel-collapse').on('shown.bs.collapse', function () {
        $(this).prev().find(".glyphicon").removeClass("glyphicon-chevron-right").addClass("glyphicon-chevron-down");
    });
    
    //The reverse of the above on hidden event:
    
    $('#accordion .panel-collapse').on('hidden.bs.collapse', function () {
        $(this).prev().find(".glyphicon").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-right");
    });
    

提交回复
热议问题