Div位置跟踪

时间:2014-04-09 08:01:15

标签: javascript jquery html

我的Senario是我有一个div名称scrollContent现在另一个div是内容,它在scrollContent div里面并且是可滚动的。在Content div中还有其他div我想跟踪内容div中所有div的位置,这样当我重新打开div内部div时,在同一位置打开。在这里,我想跟踪id =“p0”的div的位置。 我正在使用保存内容div高度和宽度     $( '#内容')。支撑( 'scrollHeight属性')     $( '#内容')。丙( 'scrollWidth')

当我重新打开时,我将保存高度和宽度分配给内容div。但内容div中的div不是精确位置。我将内容div中的div位置保存为这样     顶部= $( “#P0”)偏移()顶部。;     左= $( “#P0”)偏移()左侧;

请建议我。提前致谢

我的代码如下

<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;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

$("#p0").offset().top - $("#content").offset().top;

<强> Fiddle Example

相关问题