2012-10-01 46 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