JeffVader
JeffVader

Reputation: 702

Jquery / PHP Scroll to as page updates?

I'm using the following to run a command and output it's data as it proceeds.

$a = popen('command to run...', 'r');

while($b = fgets($a, 2048)) {
    echo "$b<br/>";
    ob_flush();flush();
}

This works fine, but I'd like my page to scroll down each time a new line is echo'd to screen.

Any idea how I can do that ?

Thanks

Upvotes: 0

Views: 732

Answers (3)

harsh4u
harsh4u

Reputation: 2600

You have to use:

$a = popen('command to run...', 'r');

while($b = fgets($a, 2048)) {
    echo "$b<br/>";
    echo "<script>
          setTimeout(function() { 
                      var scrollBottom = $(window).scrollTop() + $(window).height();
                      $(window).scrollTop(scrollBottom);}
                    ,100);
          </script>";
    ob_flush();
    flush();
}

Hope this help

Upvotes: 1

putvande
putvande

Reputation: 15213

It would be dirty but you can try this:

$a = popen('command to run...', 'r');

while($b = fgets($a, 2048)) {
    echo "$b<br/>";
    echo "<script>
          $('body').animate({
              'scrollTop': $(document).height()
          }); 
          </script>";
    ob_flush();
    flush();
}

Upvotes: 0

Arvind Bhardwaj
Arvind Bhardwaj

Reputation: 5291

Not sure how are you updating the page, but for scrolling, you can do it like this:

$('html, body').animate({
        scrollTop: $("#elementtoScrollToID").offset().top
}, 2000);

where elementtoScrollToID is the ID of new element added on the page.

Upvotes: 0

Related Questions