我的Senario是我有一个div名称scrollContent,现在另一个div是scrollContentdiv内的内容,可以滚动。在Contentdiv中还有其他div,我想跟踪Contentdiv中所有div的位置,这样当我重新打开Contentdiv内部的div时,就可以在同一位置打开。在这里,我想跟踪id="p0"的div的位置。我用保存内容div高度和宽度$('#content').prop('scrollHeight')$('#content').prop('scrollWidth')
当我重新打开时,我将保存高度和宽度分配给contentdiv。但是contentdiv内部的div并没有在确切的位置打开。我将div位置保存在内容div中,如下所示top=$("#p0").offset().top;left=$("#p0").offset().left;
请推荐我。提前感谢
我的代码如下
<div id="scrollContent">
<div id="content">
<div id="p0" class="window ui-draggable" position="absolute" style="top:256px;left:132px;"/>
</div>
</div>
Css are
#scrollContent {
border:inset 3px #EFF3FB;
overflow:scroll;
position:relative;
min-height:836px;
min-width:400px;
height:850px;
width:1020px;
left: 250px;
right: 0;
top: 15px;
margin-bottom:0px;
background-color:#EFF3FB;
}
#content {
overflow:scroll;
position:relative;
min-height:836px;
min-width:400px;
height:836px;
width:1000px;
left: 0px;
right: 0px;
top: 0px;
bottom:0px;
background-image:url('../image/new_background_content.jpg');
background-repeat:repeat;
background-image-width:100%;
z-index:0;
}
试试这个:
$("#p0").offset().top - $("#content").offset().top;
Fiddle示例