2012-10-01 44 views
0

我有一个可滚动的DIV,并在其中有一个表格。 是否可以在某种类型的onmove()方法中捕获滚动位置,以便在页面重新加载时将其放入cookie中并将滚动条恢复到相同的位置。 这里是我的JSP代码保存滚动条在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> 

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); 
     } 
    } 

但除非我打开Firebug,并设置一个断点它从我的cookie设置滚动值,它会永远去的位置'0'。我是否认为这是一个时间问题?

请忽略问题。我发现了一个JSON调用,导致我的计时问题:(

回答

0

我创建this fiddle演示如何。

+0

感谢您的答复,但它似乎我有一个时机的问题。见OP更新.. – MayoMan