jquery - keep window from changing scroll position while prepending items to a list?

前端 未结 6 946
误落风尘
误落风尘 2020-11-29 23:10

I have a page that displays messages and I want it to work just like Facebook, but without the lazy loader. Messages are displayed in chronological order, most recent last.<

6条回答
  •  北海茫月
    2020-11-29 23:26

    You could also keep the scroll position based on the offset to the bottom of the page/element.

    var ScrollFromBottom = $(document).height() - $(window).scrollTop();
    
    //ajax - add messages -- geenrate html code then add to dom
    
    //set scroll position
    $(window).scrollTop($(document).height() - ScrollFromBottom);
    

提交回复
热议问题