Automatically scroll to bottom as the page loads

前端 未结 4 526
猫巷女王i
猫巷女王i 2020-12-21 06:08

I have a php script that shows a log of its actions as the script proceeds. The log is getting quite long, up to the point where it will echo its information past the bottom

相关标签:
4条回答
  • 2020-12-21 06:10

    This works:

    <script>
    
        setTimeout(printSomething, 1000);
    
        function printSomething(){
            for(var i=0; i<10; i++){
                document.write("Hello World\n");
                document.write("<br>");
            }
            window.scrollTo(0,document.body.scrollHeight);
            setTimeout(printSomething, 1000);
        }
    </script>
    
    0 讨论(0)
  • 2020-12-21 06:17

    I think what you're looking for is this: http://www.w3schools.com/jsref/met_win_scrollto.asp

    And then, used with conjunction with this: http://www.w3schools.com/jsref/prop_element_scrollheight.asp

    You can make something like:

        function scrollToBottom{
             window.scrollTo(0, document.body.scrollHeight);
        }
    
    0 讨论(0)
  • 2020-12-21 06:19

    Every 5 seconds, it will scroll the page to the bottom of the page.

    function autoScrolling() {
       window.scrollTo(0,document.body.scrollHeight);
    }
    
    setInterval(autoScrolling, 5000); 
    // adjust the time limit based on the frequency log gets updated
      <html>
       <body>
          <script type="text/javascript">
             setInterval(function() {
                document.body.innerHTML += "<p>New log</p><br>"
             }, 5000);
          </script>
       </body>
      </html>

    0 讨论(0)
  • 2020-12-21 06:20
    function fun()
    {
     $("div").scrollTop(50);
    }
    

    now use

    <body onload="fun">
    
    0 讨论(0)
提交回复
热议问题