当数据被加载时,动态地向下滚动DIV层

时间:2022-08-24 16:49:32

I coded a chat script and I plucking my hair for couple of months to understand how a DIV layer can be scrolled down on loading some data to it using a Databinder with Repreater in ASP.NET with AJAX extensions.

我编写了一个聊天脚本,我拔了几个月的头发,以便理解如何使用一个在ASP中带有Repreater的Databinder将一些数据加载到DIV层上。净使用AJAX扩展。

I read a blog today where the author just gave me the logic but not code and I am not an expert in writing highend JavaScripts. Can anybody help me in constructing it.

我今天读了一篇博客,作者只是给了我逻辑,而不是代码,我也不是写高端java脚本的专家。谁能帮助我建造它吗?

  1. Get scroll bar position.
  2. 滚动条的位置。
  3. If scroll bar position is not bottom then move to bottom.
  4. 如果滚动条位置不是底部,则移动到底部。
  5. If scroll bar is scrolled up do no action until new item is loaded to Databinder.
  6. 如果滚动滚动滚动条,在将新项加载到Databinder之前不要执行任何操作。

Can anybody provide me with the syntax for the above three please.

谁能给我提供上述三个的语法。


Or kindly let me know if there is any other way to get rid of my issue.

或者请告诉我是否有其他方法可以解决我的问题。

1 个解决方案

#1


3  

You can use scrollTop property in native JS and $(selector).scrollTop() method in jQuery. In both cases you can assign a value to it to change the scroll position of that element.

您可以在本机JS和jQuery中的$(选择器).scrollTop()方法中使用scrollTop属性。在这两种情况下,都可以为它分配一个值,以更改该元素的滚动位置。

Example:

例子:

document.getElementById("myDiv").scrollTop = 100;
$("#myDiv").scrollTop(100);

EDIT

编辑

var div = document.getElementById('myDiv');
var scrollHeight = div.scrollHeight;
var scrollTop = div.scrollTop;
var height = parseInt(div.style.height);
if(scrollHeight - (scrollTop + height) == 0) {
    // do something when you're at the bottom
} else {
    // do something when you're NOT at the bottom
}

#1


3  

You can use scrollTop property in native JS and $(selector).scrollTop() method in jQuery. In both cases you can assign a value to it to change the scroll position of that element.

您可以在本机JS和jQuery中的$(选择器).scrollTop()方法中使用scrollTop属性。在这两种情况下,都可以为它分配一个值,以更改该元素的滚动位置。

Example:

例子:

document.getElementById("myDiv").scrollTop = 100;
$("#myDiv").scrollTop(100);

EDIT

编辑

var div = document.getElementById('myDiv');
var scrollHeight = div.scrollHeight;
var scrollTop = div.scrollTop;
var height = parseInt(div.style.height);
if(scrollHeight - (scrollTop + height) == 0) {
    // do something when you're at the bottom
} else {
    // do something when you're NOT at the bottom
}