JavaScript的机制,以自动滚动到越来越多页面的底部? [英] Javascript mechanism to autoscroll to the bottom of a growing page?

查看:123
本文介绍了JavaScript的机制,以自动滚动到越来越多页面的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望,这将是有人用的Javascript时间他们背后...

一个简单的答案

我有一个出自该日志到任何连接的浏览器在饲料新行的脚本监视的日志文件。一对夫妇的人都表示,他们希望看到的更多的是尾-f的行为 - 最新线条总是会在浏览器页面的底部,直到观众翻卷备份看到的东西。滚动回到底部应该返回到自动滚动行为。

在这一个我的谷歌三振出局是 - 希望 - 只是不知道任何东西的事关于JavaScript,因此,不知道哪些关键字来搜索。我并不需要一个完整的解决方案 - 只是一个足够接近,让我跳,并获得我的手脏

编辑:

我一直在尝试scrollTop的/ scrollHeight属性的想法,但我清楚地失去了一些东西。我已经做了旁边没有使用Javascript,如此反复,我可能会问很低级的问题:

 < HTML和GT;<身体GT;
<脚本类型=文/ JavaScript的>
对于(i = 0; I< 100;我++)
{
    文件撰写(+ I +< BR />中);
    document.scrollTop = document.scrollHeight;
}
< / SCRIPT>
< /身体GT;< / HTML>

这是许多排列之一。显然,我不能输出日志行由行的JavaScript,但我只是想看看正确的行为。什么是缺失的环节,我需要在这里?

再次编辑:
这已经变成我第一次希望一个更为有趣的问题。使用window.scroll的code的建议确实做的伎俩。我开始与限制滚动只发生在浏览器是在文档主体的底部播放。这是很容易在理论上做的,但在实践中碰到一个障碍:

每当你从服务器获得新的文本时,身体大小的增加和当前滚动位置不再在文档的底部。你不能再有什么区别(使用scrollHeight属性,clientHeight和scrollTop的)用户是否已经向上滚动或文本刚刚出手超出了他们的看法。

我觉得如果这是去工作,我将不得不对自己承诺有一个JS事件当用户滚动和关闭,如果他们是窗口的底部上方滚动,但把它火灾背面上,如果他们向下滚动到他们有效地是在视图的底部的点。我期待在onScroll事件,因为在变量我提到的数学工作了pretty很好,我觉得我是在正确的道路在这里。感谢您的输入,大家好!


解决方案

  X = 0; //水平坐标
Y = document.height; //垂直坐标
window.scroll(X,Y);

Hopefully, this will be an easy answer for someone with Javascript time behind them...

I have a log file that is being watched by a script that feeds new lines in the log out to any connected browsers. A couple people have commented that what they want to see is more of a 'tail -f' behavior - the latest lines will always be at the bottom of the browser page until the viewer scrolls back up to see something. Scrolling back to the bottom should return you to the auto-scrolling behavior.

My google strikeout on this one is - hopefully - just a matter of not knowing anything at all about javascript and therefore, not knowing what keywords to search for. I don't need a complete solution - just a 'close enough' that lets me jump in and get my hands dirty.

EDIT:

I've been attempting the scrollTop/scrollHeight idea, but am clearly missing something. I've done next to nothing with Javascript, so again I'm probably asking very low-level questions:

<html><body>
<script type="text/javascript">
for (i=0; i<100; i++)
{
    document.write("" + i + "<br />");
    document.scrollTop = document.scrollHeight;
}
</script>
</body></html>

This was one of many permutations. Obviously, I can't output the log line-by-line in javascript, but I'm just trying to see the correct behavior. What's the missing link I need here?

EDIT AGAIN: This has turned into a far more interesting problem that I first expected. The code suggestion using window.scroll does do the trick. I started playing with restricting the scroll to only take place when the browser was at the bottom of the document body. This is easy enough to do in theory, but in practice it hits a snag:

Every time you get new text from the server, the size of the body increases and your current scroll position is no longer at the bottom of the document. You can no longer tell the difference (using scrollHeight, clientHeight and scrollTop) whether the user has scrolled up or if the text has just shot beyond their view.

I think that if this is going to work, I'm going to have to commit myself to having a JS event that fires when the user scrolls and turns off scrolling if they are above the bottom of the window, but turns it back on if they have scrolled down to the point where they are effectively at the bottom of the view. I'm looking at the onScroll event and, given that the math on the variables I mentioned works out pretty well, I think I am on the right path here. Thanks for your input, everyone!

解决方案

x = 0;  //horizontal coord
y = document.height; //vertical coord
window.scroll(x,y);

这篇关于JavaScript的机制,以自动滚动到越来越多页面的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆