Bootstrap collapse - go to top of the open item?

前端 未结 6 1673
孤街浪徒
孤街浪徒 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:33

    You can try this:

    I used the following, works like a charm:

    $("#accordion2").bind('shown', function() {
            var active=$("#accordion_univlist .in").attr('id');
            scrollhere('#'+active);
            $('.closebutton-right').hide(); 
    }); 
    
    $('.accordion-heading').click(function () { 
      // Do something if you want to do on click  else ignore this handler.
    }
    
    function scrollhere(destination){
        var stop = $(destination).offset().top - 80;
        var delay = 1000;
        $('body,html').animate({scrollTop: stop}, delay);
        return false;
    }
    

    It also gives a bounce effect, and I like it.

提交回复
热议问题