【发布时间】:2011-12-12 17:07:54
【问题描述】:
我只是在使用基本级别的 javascripts。今天,当新数据添加到 DIV 时,我发现了以下内容并向下滚动 DIV 层。我不明白如何调用函数。是否要使用window.onload 函数?或任何其他。我应该在哪里声明 DIV 名称?
代码如下。
var chatscroll = new Object();
chatscroll.Pane =
function(scrollContainerId)
{
this.bottomThreshold = 25;
this.scrollContainerId = scrollContainerId;
}
chatscroll.Pane.prototype.activeScroll =
function()
{
var scrollDiv = document.getElementById(this.scrollContainerId);
var currentHeight = 0;
if (scrollDiv.scrollHeight > 0)
currentHeight = scrollDiv.scrollHeight;
else
if (objDiv.offsetHeight > 0)
currentHeight = scrollDiv.offsetHeight;
if (currentHeight - scrollDiv.scrollTop - ((scrollDiv.style.pixelHeight) ? scrollDiv.style.pixelHeight : scrollDiv.offsetHeight) < this.bottomThreshold)
scrollDiv.scrollTop = currentHeight;
scrollDiv = null;
}
更新 1:
<script type="text/javascript">
var chatscroll = new Object();
var chatScrollPane = new chatscroll.Pane('div1');
chatScrollPane.activeScroll()
chatscroll.Pane = function (scrollContainerId) {
this.bottomThreshold = 25;
this.scrollContainerId = scrollContainerId;
}
chatscroll.Pane.prototype.activeScroll = function () {
var scrollDiv = document.getElementById(this.scrollContainerId);
var currentHeight = 0;
if (scrollDiv.scrollHeight > 0)
currentHeight = scrollDiv.scrollHeight;
else
if (objDiv.offsetHeight > 0)
currentHeight = scrollDiv.offsetHeight;
if (currentHeight - scrollDiv.scrollTop - ((scrollDiv.style.pixelHeight) ? scrollDiv.style.pixelHeight : scrollDiv.offsetHeight) < this.bottomThreshold)
scrollDiv.scrollTop = currentHeight;
scrollDiv = null;
}
</script>
【问题讨论】:
-
我认为您需要 Jquery 才能实现上述功能。
-
@CharmingPrince 如果您发布了关于斑马的帖子,那么准确度再低。不管你信不信,这里不涉及 jQuery。 :P
-
@Chris 从评论中可以清楚地看到,我说“我认为”?其中不确定。既然错了,就这样吧,我不是 JavaScript 专家。
-
那为什么还要评论呢?我不怪你不知道——有很多事情我不知道。我的问题是你告诉某人一些明显错误的事情,来自对手头主题的无知。比传播不准确的信息更好地观察和学习。
-
@Chris 这就是为什么它被称为评论,我没有给出答案,如果我在答案字段中写了这个,那么你可以说任何你想要的。很高兴知道你不知道一切,因为有没有这样的人,如果有人发表了错误的评论,你不必大喊大叫,就像@SLaks - 只是说“错误” - 保持简单我会理解我的错误并从中学习而不是方式你正在接受它。所以冷静一下。
标签: javascript html function declaration invocation