2010-12-17 80 views
0

當div被拖動到滾動出現然後被調整大小的點時,它會忘記它的實際位置並相對於視口重新定位。如何保持其實際位置?jQuery:相對於視口重新定位

<!DOCTYPE HTML> 
<html> 
<head> 
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js" type="text/javascript"></script> 
<script> 
(function($){$(document).ready(function(){ 
    $('#theDiv').draggable().resizable(); 
})})(jQuery); 
</script> 
</head> 
<body> 
    <div id="container" style="position:relative;width:600px;height:600px;border:solid 1px #000;overflow:auto;"> 
     <div id="theDiv" style="width:200px;height:200px;border:solid 1px #000;"></div> 
    </div> 
</body> 
</html> 

回答

0

你嘗試這個

就可以計算出位置,並傳遞給scrollTop的

$("#divid").scrollTop(300); // 300 is just a sample