Scroll back to the top of scrollable div

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


        
相关标签:
15条回答
  • 2020-12-07 14:21

    The ID Should have the id of the corresponding div that has the overflow css property.

    document.querySelector('#YOUR_OVERFLOWED_DIV').scrollTop = 0;

    0 讨论(0)
  • 2020-12-07 14:26

    Another way to do it with a smooth animation is like this

    $("#containerDiv").animate({ scrollTop: 0 }, "fast");
    
    0 讨论(0)
  • 2020-12-07 14:29

    For those who still can't make this work, make sure that the overflowed element is displayed before using the jQuery function.

    Exemple:

    $('#elem').show();
    $('#elem').scrollTop(0);
    
    0 讨论(0)
提交回复
热议问题