我有一个HTML页面,其中有一个< div>,其中包含比本身更宽的内容; “溢出:隐藏”的样式使多余部分不可见。避免在IE中通过键盘导航触发不需要的滚动?
这个内容可以有链接。在IE8(但不是Firefox 3.6)中,如果您使用键盘(即Tab键)将焦点设置为右侧边缘处的链接,则IE会将整个div向左滚动足够多,以使整个链接可见。 (同样的事情发生在左边的链接获得焦点时,如果div已经被向左滚动 - 它会滚动内容以使整个链接可见)。
我可以尝试隐藏这种不需要的滚动通过设置div的scrollLeft值,当它离开重击--jQuery使这很容易。但是,如果可能的话,我宁愿使用样式或设置来首先防止滚动。如前所述,Firefox在获得焦点时不会将部分剪切的链接滚动到视图中。理想情况下,应该使IE的行为方式相同。
下面的示例HTML。在IE中,使用Tab(或Shift + Tab)依次为每个链接设置焦点,以查看框的移动内容。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo of undesired scrolling</title>
</head>
<body>
<a href="http://www.w3.org">Before</a>
<div style="width: 400px; border: 1px solid gray; overflow: hidden;">
<div>
<div style="width: 450px; text-align: center;">
<a href="http://www.w3.org">Somewhere in the middle</a>
</div>
<div style="width: 450px; text-align: left;">
<a href="http://www.w3.org">Over on the left</a>
</div>
<div style="width: 450px; text-align: right;">
<a href="http://www.w3.org">Over on the right</a>
</div>
</div>
</div>
<a href="http://www.w3.org">After</a>
</body>
</html>
在此先感谢您的任何见解!
这与[我刚刚问过的问题]非常相似(http://stackoverflow.com/q/13827409/925897)。 – brentonstrine 2012-12-11 20:10:12