Scroll Automatically to the Bottom of the Page

后端 未结 24 2839
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 05:22

Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page.

For a matter of fact, I do know

24条回答
  •  一整个雨季
    2020-11-22 06:00

    I have an Angular app with dynamic content and I tried several of the above answers with not much success. I adapted @Konard's answer and got it working in plain JS for my scenario:

    HTML


    Details for Customer 1




    CSS

    body {
        background: #20262E;
        padding: 20px;
        font-family: Helvetica;
    }
    
    #app {
        background: #fff;
        border-radius: 4px;
        padding: 20px;
        transition: all 0.2s;
    }
    

    JS

    function scrollToBottom() {
        scrollInterval;
        stopScroll;
    
        var scrollInterval = setInterval(function () {
            document.documentElement.scrollTop = document.documentElement.scrollHeight;
        }, 50);
    
        var stopScroll = setInterval(function () {
            clearInterval(scrollInterval);
        }, 100);
    }
    

    Tested on the latest Chrome, FF, Edge, and stock Android browser. Here's a fiddle:

    https://jsfiddle.net/cbruen1/18cta9gd/16/

提交回复
热议问题