Scroll back to the top of scrollable div

后端 未结 15 1347
独厮守ぢ
独厮守ぢ 2020-12-07 14:02
#containerDiv          


        
15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 14:03

    As per François Noël's answer "For those who still can't make this work, make sure that the overflowed element is displayed before using the jQuery function."

    I had been working in a bootstrap modal that I repeatedly bring up with account permissions in a div that overflows on the y dimension. My problem was, I was trying to use the jquery .scrollTop(0) function and it would not work no matter how I tried to do it. I had to setup an event for the modal that didn't reset the scrollbar until the modal had stopped animating. The code that finally worked for me is here:

        $('#add-modal').on('shown.bs.modal', function (e) {
            $('div.border').scrollTop(0);
        });
    

提交回复
热议问题