如何使滚动条始终保持在页面底部

how to keep scroll bar always to bottom of page

本文关键字:底部 始终保持 何使 滚动条      更新时间:2023-09-26

使滚动条始终位于我使用的页面底部

$(document).ready(function() {
    $(function() {
        $("html, body").animate({ scrollTop: $(document).height() }, "fast"); 
    });
});

它在火狐中工作,但在铬中不起作用。为什么它在chrome中不起作用,任何人都可以向我建议保持滚动条始终位于页面底部的好解决方案。

感谢您的任何帮助

如果你想回到

页面底部,即使用户试图向上滚动,你将需要按间隔调用你的函数。

$(document).ready(function() {
    function scrollBottom(){
        $("html, body").animate({ scrollTop: $(document).height() }, "fast");
    }
    setInterval(scrollBottom, 500);
});

您可以使用间隔来获得所需的 UI 交互量。

或者,您可以绑定到 scroll 事件,这将在用户滚动时触发。

$(document).ready(function() {
    $(window).scroll(function(){
        $("html, body").animate({ scrollTop: $(document).height() }, "fast");
    });
});