[英]Saving the position of a scroll bar in a JSP page
I have a DIV that is scrollable and have a table inside this. 我有一个可滚动的DIV,并且其中有一个表格。 Is it possible to capture the scroll position in some type of onmove() method so I can put it in a cookie and restore the scroll bar to the same position when the page reloads. 是否可以通过某种onmove()方法捕获滚动位置,所以我可以将其放置在cookie中,并在重新加载页面时将滚动条恢复到相同位置。 Here is my JSP code 这是我的JSP代码
<div id="wordListTableDiv" style="overflow: auto;height: 700px; width: 320px; max-width:320px; border:2px solid black; background-color: #FFFFF0; padding: 10px">
<br>
<div>
<br>
<input type="button" value="Show All" onclick="getWordList()" style="float: left;">
<input type="button" value="Hide Ignored and Good" onclick="hideIgnoredAndGoodWords();" style="float: right;">
</div>
<br></br>
<table id="wordListTable" border=1 >
<thead id="wordListTableHead"><tr>
<th width="150">Word</th>
<th width="150">State</th>
</tr></thead>
<tbody><%-- Empty to begin with, filled by JavaScript. --%></tbody>
</table>
</div>
The JavaScript I have is 我拥有的JavaScript是
function setScrollPosition()
{
//If the scroll position was set previously then reposition it to the old value.
var scrollPosition = readCookie("scrollPositionCookie");
if( scrollPosition != null )
{
$("#wordListTableDiv").scrollTop( scrollPosition );
}
}
but unless I open firebug and set a break point where it sets the scroll value from my cookie it will always go to position '0'. 但是,除非我打开Firebug并设置一个断点(该断点用于设置Cookie的滚动值),否则它将始终转到位置“ 0”。 Am I correct in thinking this is a timing issue? 我认为这是时间问题是否正确?
Please ignore Question. 请忽略问题。 I've spotted a JSON call that is causing my timing issue :( 我发现了导致我的计时问题的JSON调用:(
我创建了这个小提琴来演示如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.