Bootstrap collapse - go to top of the open item?

前端 未结 6 1671
孤街浪徒
孤街浪徒 2021-02-01 07:48

I\'m using the bootstrap collapse function, but when I open an element which has a lot of content, then open the next element, it jumps down and doesn\'t go to the top of the op

6条回答
  •  日久生厌
    2021-02-01 08:24

    I have scrollto working with bootstrap collapse but the code is for WordPress. I brought in your content and it works. Bootstrap Collapse has a shown event and then you need to know the height of the content to scroll up.

    $(".accordion-body").on("shown", function () {
        var selected = $(this);
        var collapseh = $(".collapse .in").height();
        $.scrollTo(selected, 500, {
            offset: -(collapseh)
        });
    });
    

    You may need to tweak it a bit but it should work.

提交回复
热议问题