jQuery“空"更改滚动条

问题描述:

我正在使用来自服务器的ajax调用来更新内容. 更新后,我清空包含数据的包装div,然后再次用新数据填充它. 到目前为止,一切都很好. 问题是-

i am updating content with ajax call from server. after the update, i empty the wrapper div, that contains the data, and fill it again with the new data. so far so good. the problem is - that on a

$('#MessagesContainer').empty();

方法-滚动条变回原来的状态. 因此,如果某人想添加数据并且他位于页面底部,则滚动会向上滚动.

method - the scrollbar changes back up. so if someione want to add data and he is in the bottom of the page, the scroll goes back up.

此操作很有意义,但是对于此特定操作,我想避免它,因为它不是那么用户友好".

this action makes sense, but for this particular action i want to avoid it since it's not so "user-friendly".

好,谢谢您的回答. 使用.html()可能比.empty()更好,然后重新添加数据. 但是,事实是,对于我的实现来说,这是不可能的.

well, thanks for your answers. use .html() would probably be better than .empty() and re-append the data. but, the thing is that for my implementation that is not possible.

所以我做了什么

.RemoveAfter(x) function

删除集合中索引"x"之后的所有元素,然后从该"x"索引附加数据.做到了.滚动条保持在原位置.这并不是100%的用户友好性,因为它会使某些数据消失一毫秒然后又返回,但就目前而言,这是我能想到的最好的方法.

that remove all the elements after index 'x' in the collection and then append data from this 'x' index. that did the trick. the scrollbar stays where it is. it's not 100% percent user-friendly since it make some of the data disappear for a milisecond and then it comes back, but at this currently point, it's the best i could think of.