duanci9305 2013-04-01 16:45
浏览 142

div刷新后需要停止自动滚动到顶部

I am trying to get a div that refreshes every 2 seconds to stop scrolling back to the top after the 2 second refresh I have PHP code and javascript. The Javascript I am using is:

function at_Ticket_scrollBottom()
{
   var objDiv = document.getElementById("cartTicket");
   objDiv.scrollTop = objDiv.scrollHeight;
}

function at_Tabs_Update()
{

if(div_WPOSVar_IsVisible())
{
    //calling setTimeout without clearing any existing timeout can add multiple calls.
    //IE the normal 2 second sequence, then call at_Tabs_Update two more times, and
    //     now we have 3 timeouts set to call at_Tabs again, etc.
    //This wouldn't be an issue except that we call at_Tabs_Update directly to cause
    //     immediate refresh from many places.
    //So clear the handle everytime to get rid of the last one we set.
    clearTimeout(at_Tabs_Timer);
    at_Tabs_Timer=setTimeout("at_Tabs_Update()", 2*1000); //every 2 seconds
    return;
}
}

So after the refresh if I scroll down to the bottom of the ticket it jumps back to the top after the next refresh so I can never get to the bottom and select an item and edit it before the refresh how do I stop the auto scroll back to the top.

  • 写回答

1条回答 默认 最新

  • duaabhuv188411 2013-04-03 22:51
    关注

    from the scars infos I can gather here I think your best bet would be to save your current scroll position before you refresh and after the ajax call scroll to that saved position. use jQuerys .scrollTop() function for both reading and setting the scroll.

    some pseudo code for illustration:

    at ajax refresh function
        var curPos $(element).scrollTop();
        ... do ajax call ..
            ajax callback: $(element).scrollTop(curPos);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件