每次向上滚动重新加载数据

Scroll up in reload data every time

本文关键字:加载 数据 新加载 滚动      更新时间:2023-09-26

这是我的代码:

var j = jQuery.noConflict();
j(document).ready(function()
{
    j("#refresh").everyTime(3000, function(I)
    {
        j.ajax(
        {
          url: "refresh.php",
          cache: false,
          success: function(html)
          {
              j("#refresh").html(html);     
              var newscrollHeight = j("#refresh").attr("scrollHeight") - 20;
              j("#refresh").animate({scrollTop: newscrollHeight },      'normal'); //scrol otomatisnya                      
          }
        });
    });     
});

我想向上滚动我的滚动,但不能,因为 #refresh 每 3000 次重新加载一次。有人知道如何解决这个问题吗?

我会以不同的方式做,如果需要,请在滚动到顶部后让成功处理程序在 3 秒后调用相同的方法。

尝试这样的事情:

var j = jQuery.noConflict();
j(document).ready(function()
{
      Refresh();
});     
function refresh()
{
    j.ajax(
    {
      url: "refresh.php",
      cache: false,
      success: function(html)
      {
          j("#refresh").html(html);     
        //  var newscrollHeight = j("#refresh").attr("scrollHeight") - 20;
         // j("#refresh").animate({scrollTop: newscrollHeight },'normal'); //scrol otomatisnya   
          var div = $('#refresh');
          div.scrollTop(div.prop("scrollHeight") - 20);
          setTimeout(function()
          {
              Refresh();
          },3000);  // or how ever long     
      }
    });
}
更新

:我更新了滚动代码