Jquery .scrollTop() not working

六月ゝ 毕业季﹏ 提交于 2019-12-06 00:29:53

Browser do not re-render all content when the HTML is changed, there is always a small gap.If there was no gap the javascript execution would block the browser and the user couldn't use your page (as intended). <- This could be the reason :)

You can try:

$.ajax({
url: 'getLog.php',
data: {'logFile': 'log.php'}, // echo "<ul> A BUNCH OF <li>s here </ul>"
success: function(data){
    $("#my-div").html(data);
    // console.log($("#my-div ul")[0].scrollHeight); // Debugging Purposes
    setTimeout(function() {
       $("#my-div ul").scrollTop($("#my-div ul")[0].scrollHeight);
    }, 10);
}
});

If that was the problem you can also try to lower the time inside setTimeout to 0 - it will not be 0 but the minimal time each browser sets.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!