2010-12-17 92 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