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 –