0
每当页面刷新时,我都会维护div“currentinfo”的滚动位置。 但是,当新数据添加到div时,我想滚动到div的底部。这怎么可能?只有在将新数据添加到div时滚动到div的底部
<form id="form1" runat="server"><asp:ScriptManager ID="manager" ScriptMode="Release" runat="server" ></asp:ScriptManager>
<script type="text/javascript">
// It is important to place this JavaScript code after ScriptManager1
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args) {
if ($get('<%=currentinfo.ClientID%>') != null) {
// Get X and Y positions of scrollbar before the partial postback
xPos = $get('<%=currentinfo.ClientID%>').scrollLeft;
yPos = $get('<%=currentinfo.ClientID%>').scrollTop;
}
}
function EndRequestHandler(sender, args) {
if ($get('<%=currentinfo.ClientID%>') != null) {
// Set X and Y positions back to the scrollbar
// after partial postback
$get('<%=currentinfo.ClientID%>').scrollLeft = xPos;
$get('<%=currentinfo.ClientID%>').scrollTop = yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
</script>
....
......
</form>
我已经使用了,但问题是该分区将保持它的滚动位置,将滚动到第二个从底部只有 –
“滚动到第二个”是什么意思?我创建了一个jsfiddle,http://jsfiddle.net/u4aZw/ – Andrew
好的,我给你一个链接,在这里给出更多的细节问题 http://stackoverflow.com/questions/20138854/maintain-the-scroll div-and-scroll-to-bottom-of-div-if-new-data-is-a –