2012-04-22 30 views
0

我有一個jQueryUI對話框,其內容超過了默認的高度(所以它在對話框中滾動),在底部有一個提交按鈕。我使用ajaxstart來顯示加載屏幕,但由於對話滾動,你看不到加載div,除非我點擊按鈕並手動滾動到頂部。使用jQuery滾動到燈箱div頂部

我希望能夠在單擊事件時滾動到對話框中div的頂部。我有以下的代碼,我試圖(但沒有成功):由Ohgodwhy

#loading { 
z-index: 200; 
display:none; 
position:absolute; 
left:0px; 
top:0px; 
width:100%; 
height:100%; 
background-color:#000000; 

/* Theoretically for IE 8 & 9 (more valid) */ 
/* ...but not required as filter works too */ 
/* should come BEFORE filter */ 
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; 

/* This works in IE 8 & 9 too */ 
/* ... but also 5, 6, 7 */ 
filter: alpha(opacity=70); 

/* Older than Firefox 0.9 */ 
-moz-opacity:0.5; 

/* Safari 1.x (pre WebKit!) */ 
-khtml-opacity: 0.5; 

/* Modern! 
/* Firefox 0.9+, Safari 2?, Chrome any? 
/* Opera 9+, IE 9+ */ 
opacity: 0.5; 
} 

// jQuery Script: 
$("input[name='docSubmit']").click(function() { 
      var height = $("#attendeeManual").height(); 
      $("#loading").css("height",height); 
      $('html, body').animate({scrollTop:$('#attendeeManual').offset().top - 20}, 'slow'); 
     }); 
+0

捕獲具有滾動條的窗口的ID或Class。然後使用'$('#thisWindow')。scrollTop(0);'滾動到該元素的頂部。 – Ohgodwhy 2012-04-22 17:19:56

回答

1

按照建議,一個簡單的$("#div").scrollTop(0)帶你到div的最頂端。我已經讀過,這可以是動畫,但爲我的目的,我只需要它回到頂端,沒有別的:)謝謝!