【问题标题】:Need workaround for invalid getBoundingClientRect() of span in IE6 and IE7 in RTL mode在 RTL 模式下 IE6 和 IE7 中的无效 getBoundingClientRect() 需要解决方法
【发布时间】:2013-02-18 09:04:06
【问题描述】:

我正在寻找以下问题的解决方法:

当文档处于 RTL 模式时,当我尝试将 getBoundingClientRect() 用于带有边框 <span id="hello_id" style="border-bottom:dotted 1px">helo</span> 的跨度时,我得到无效值。

以下代码显示了一个示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function show_rectangle()
{
    var el = document.getElementById('hello_id');
    var rec = el.getBoundingClientRect();
    alert('Left:' + rec.left + ' Right:' + rec.right);
}
setTimeout(show_rectangle,2000);
</script>
</head>
<body style="direction:rtl">
<p id='xxx' style="text-align:center"><span id="hello_id" style="border-bottom:dotted 1px">hello</span></p>
</body>
</html>

在 IE6 和 IE7 中,警报显示为“左:-621 右:-593”

当我从 Body 的样式或跨度的样式属性中删除“direction:rtl”时,我得到了合理的正值。

如何解决此问题:即如何在 rtl 文档中创建带边框的跨度并具有正确的边界矩形?或者也许生成一个没有这个属性的边框?

【问题讨论】:

    标签: javascript internet-explorer right-to-left


    【解决方案1】:

    解决方案是将一个跨度放在另一个跨度内,将边框样式设置为内部跨度并测量外部:

    <p id='xxx' style="text-align:center"><span id="hello_id" ><span style="border-bottom:dotted 1px">hello</span></span></p>
    

    比它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      相关资源
      最近更新 更多