滚动顶部未设置为iframe内的div。得0分

时间:2013-11-08 07:40:32

标签: jquery iframe scrolltop

<iframe id="iframe" scrolling="no" src="abc.aspx" class="cssTable" runat="server"
            style="width: 280px; height: 522px;"></iframe>

// Div在iframe中加载。 abc.aspx内容

<div id="divScroll" style="overflow-x: hidden; width: 50%;height:150px;" class="cssDiv">
  <table>
    <tr><td>item 1</td></tr>
    <tr><td>item 2</td></tr>
    <tr><td>item 3</td></tr>
    <tr><td>item 4</td></tr>
    <tr><td>item 5</td></tr>
    <tr><td>item 6</td></tr>
    <tr><td>item 7</td></tr>
    <tr><td>item 8</td></tr>
    <tr><td>item 9</td></tr>
    <tr><td>item 1</td></tr>
    <tr><td>item 2</td></tr>
    <tr><td>item 3</td></tr>
    <tr><td>item 4</td></tr>
    <tr id="selectedTR"><td>item 5</td></tr>
    <tr><td>item 6</td></tr>
    <tr><td>item 7</td></tr>
    <tr><td>item 8</td></tr>
    <tr><td>item 9</td></tr>
  </table>
</div>

//jquery
    var $divScroll = $('#divScroll');
    var $matchedRow= $('#selectedTR');
    $divScroll.scrollTop($matchedRow.offset().top - $matchedRow.parent().offset().top - $matchedRow.parent().scrollTop());

    alert($divScroll.scrollTop())//Always getting 0

In Demo link Div was not inside iframe so top set fine but when div inside iframe always getting 0

0 个答案:

没有答案