当表在IE中获得焦点时,表滚动条会跳起

Mic*_*elS 7 html javascript internet-explorer html-table internet-explorer-9

问题:我有一个table用包装div带overflow-y : auto,一旦table获得焦点,滚动条跳起来.我怎么能阻止这个?

我在IE9中遇到过这种行为,而不是在Chrome中.

请注意:我已添加tabindex到表中,以便它可以获得焦点.点击它就可以专注于桌面.

jsFiddle: http ://jsfiddle.net/msdevs/r6TzS/4/

  1. 向下滚动表格
  2. 单击页面上的其他元素,以便关注表格
  3. 单击表格以关注它
  4. 滚动条跳起来

HTML:

    <div>
        <table id="tabl" tabindex="1">
            <thead>
                <tr>
                    <th style="font-weight: bold">head</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>first</td>
                </tr>
                <tr>
                    <td>SEC</td>
                </tr>
                <tr>
                    <td>dsadfawdfadfa</td>
                </tr>
                <tr>
                    <td>dsadfawdfadfa</td>
                </tr>
.
.
.
                 <tr>
                    <td>dsadfawdfadfa</td>
                </tr>
            </tbody>
        </table>
    </div>
Run Code Online (Sandbox Code Playgroud)

CSS:

table {
    table-layout: fixed;
    font-family: arial;
    font-size: 11px;
    text-align: left;
    outline: none;
    width: 625px;
}
div {
    overflow-y: auto;
    overflow-x: hidden;
    height: 150px;
    width: 300px
}
Run Code Online (Sandbox Code Playgroud)

JS:

$('table').focusin(function (e) {
    console.log("table got focus - scroller jumps up");
}).click(function () {
    $('table').focus();
});
Run Code Online (Sandbox Code Playgroud)

rob*_*obC 7

这为我修复了它 - 保留包装器上当前滚动位置的记录,并在模糊时重新设置它.

http://jsfiddle.net/r6TzS/10/

$('#wrapper').scroll(function(){
    $(this).data( {posY: $(this).scrollTop()} )
})
.blur(function(){
    $(this).scrollTop( $(this).data("posY") );
})
Run Code Online (Sandbox Code Playgroud)