jQuery“空"更改滚动条 [英] jquery "empty" changes the scrollbar

查看:93
本文介绍了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.

这篇关于jQuery“空"更改滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆