Raphael.js函数getBBox在IE8中返回NAN / NAN / NAN [英] Raphael.js function getBBox give back NAN/NAN/NAN in IE8
问题描述
使用Raphaël2.1.4 - JavaScript矢量库
执行类似的操作:
using Raphaël 2.1.4 - JavaScript Vector Library do something like that:
var textDummy = paper.text(50,500, 'hello world').attr({fill: 'transparent', 'font-size': 14});
var textBox = textDummy.getBBox();
使用chrome和firefox一切都很好,
但在IE8中它会回馈NaN / NaN / NaN,
par例如textBox.height是NaN。
with chrome and firefox everything is fine, but in IE8 it give back NaN/NaN/NaN, par exemple textBox.height is NaN.
我如何解决这个问题?
推荐答案
我在Rapahel 2.2.0和2.2.1中遇到了同样的问题,使用 ._ getBBox()
没有修复它为了我。
I had the same problem in Rapahel 2.2.0 and 2.2.1, and using ._getBBox()
didn't fix it for me.
为我修复的是回退到 .auxGetBBox()
如果已定义且常规 .getBBox()
不起作用,如下所示:
What did fix it for me is falling back to .auxGetBBox()
if it's defined and regular .getBBox()
doesn't work, like this:
var bbox = path.getBBox( );
// Workaround for apparent bug in Raphael's VML module's getBBox() override
if( isNaN( bbox.x ) && path.auxGetBBox ){
bbox = path.auxGetBBox();
}
我没有修复了底层错误,但我找到了它的来源。
I don't have a fix for the underlying bug, but I have found the source of it.
在VML模式下,Raphael采用初始 getBBox()
函数,在元素原型上将其保存为 auxGetBBox()
,然后将其替换为看似已损坏的函数。
In VML mode, Raphael takes the initial getBBox()
function, saves it as auxGetBBox()
on the element prototype, then replaces it with a function that appears to be broken.
它的计算基于一个定义为的变量var z = 1 / this.paper._viewBoxShift.scale;
,显然希望_viewBoxShift.scale是当前视图框与初始视图框相比规模的一些因素,但实际上 _viewBoxShift.scale
是这样的对象,看起来像来自 paperproto.getSize()
:
It has calculations based on a variable defined as var z = 1/this.paper._viewBoxShift.scale;
, which clearly expects _viewBoxShift.scale to be some factor of the scale of the current viewbox compared to the initial viewbox , but actually _viewBoxShift.scale
is an object like this which appears to come from paperproto.getSize()
:
{height:someNumber,width:someNumber }
这是所有 NaN
的来源。 Cannae除以一个对象。
This is where all the NaN
s are coming from. Cannae divide by an object.
因此,如果使用视图框不应用缩放,这种解决方法可以正常工作,但如果应用了缩放,可能会给出不正确的结果(我能做的事情)在VML模式的raphael最新版本中完全可以工作,但这是一个单独的问题。修复 将深入挖掘Raphael的VML模块,将适当的缩放因子输入到 z
变量中。
So this workaround works fine if no zoom is applied using a viewbox, but may give incorrect results if a zoom has been applied (something I can't get to work at all in recent versions of raphael in VML mode, but that's a seperate question). Fixing that will involve digging deep into Raphael's VML module to pipe a proper zoom factor into this z
variable.
这篇关于Raphael.js函数getBBox在IE8中返回NAN / NAN / NAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!