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/
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)
这为我修复了它 - 保留包装器上当前滚动位置的记录,并在模糊时重新设置它.
$('#wrapper').scroll(function(){
$(this).data( {posY: $(this).scrollTop()} )
})
.blur(function(){
$(this).scrollTop( $(this).data("posY") );
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5511 次 |
| 最近记录: |