Twitter bootstrap collapse: change display of toggle button

后端 未结 10 689
有刺的猬
有刺的猬 2020-12-12 23:50

I am using Twitter Bootstrap to create collapsible sections of text. The sections are expanded when a + button is pressed. My html code as follows:

<         


        
10条回答
  •  有刺的猬
    2020-12-13 00:18

    I guess you could look inside your downloaded code where exactly there is a + sign (but this might not be very easy).

    What I'd do? I'd find the class/id of the DOM elements that contain the + sign (suppose it's ".collapsible", and with Javascript (actually jQuery):

    
    

    edit Alright... Sorry I haven't looked at the bootstrap code... but I guess it works with something like slideToggle, or slideDown and slideUp... Imagine it's a slideToggle for the elements of class .collapsible, which reveal contents of some .info elements. Then:

             $(".collapsible").click(function() { 
                 var content=$(".collapsible").html();
                 if $(this).next().css("display") === "none") { 
                     $(".collapsible").html(content.replace("+", "-"));
                 }
                 else $(".collapsible").html(content.replace("-", "+"));
             });
    

    This seems like the opposite thing to do, but since the actual animation runs in parallel, you will check css before animation, and that's why you need to check if it's visible (which will mean it will be hidden once the animation is complete) and then set the corresponding + or -.

提交回复
热议问题