2

我的代码在下面......

 <cufon class="cufon cufon-canvas" alt="John " style="width: 59px; height: 24px;">
   <canvas width="76" height="25" style="width: 76px; height: 25px; top: 0px; left: -1px;"></canvas>
<cufontext>
      <cufon class="cufon cufon-canvas" alt="John " style="width: 5px; height: 1px;">
      <canvas width="6" height="2" style="width: 6px; height: 2px; top: 0px; left: 0px;"> </canvas>
             <cufontext>John </cufontext>
  </cufon>
</cufontext>

我需要得到正确的 boundingClientRect 对象..

我正在尝试下面的代码,但它为 rect.left 和 rect.right 提供负值..

if(documentNode.createRange){

 var range = documentNode.createRange();

 range.selectNodeContents(textNode);

 if (range.getBoundingClientRect)
 {
        var rect = range.getBoundingClientRect();

        if (rect)
        {

                            y = rect.top;
                            h = rect.bottom - rect.top;
                            w = rect.right - rect.left;
                            x = rect.left;
                    }
            }
    }

请帮忙

4

0 回答 0