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
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
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.
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.