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

时间:2013-10-05 15:59:39

标签: javascript jquery css scrollbar

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

$(document).ready(function() {

    $(function() {

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

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

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

如果您想要回到页面底部,即使用户尝试向上滚动,您也需要在一段时间内调用您的函数。

$(document).ready(function() {

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

    setInterval(scrollBottom, 500);

});

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

或者,您可以绑定到滚动事件,只要用户滚动就会触发。

$(document).ready(function() {

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

});