javascript - 拉斐尔的不透明度超出范围(负值)

标签 javascript raphael max

我有一个页面抛出 JavaScript 异常:

Unhandled exception at line 5144, column 13 in raphael.js
0x80048270 - JavaScript runtime error: Arg: Fraction out of range (0 to 1 allowed)

I'm using version 2.1.0 of Raphaël, and for debugging purposes using the uncompressed JavaScript file not the minimized one (i.e. the one copied from http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael.js)

If I break into a debugger (I'm using Visual Studio 2012) I find that the value of the variable 'opacity' is -0.23185589076263113 while it should be between 0 and 1. But I cannot see how it got to be negative. Here's the code (from raphael.js, i.e. it's library code not my code)

        opacity = mmin(mmax(opacity, 0), 1);
        params["stroke-width"] == null && (width = a["stroke-width"]);
        params["stroke-width"] && (stroke.weight = width);
        width && width < 1 && (opacity *= width) && (stroke.weight = 1);
        stroke.opacity = opacity;

当第一行明确将其限制为 [0, 1] 时,如何在这段代码的最后一行使用 opacity == -0.23185589076263113 ?

(注意,在 raphael.js 中,mmax 是 math.max,mmin 是 math.min。)

最佳答案

找到了。

width && width < 1 && (opacity *= width) && (stroke.weight = 1); 
如果宽度为负(在本例中为负),则

会破坏不透明度范围。宽度在我引用的 block 之前的行上设置(5139):

var width = (toFloat(params["stroke-width"]) || 1) * .75;

我需要调试我的代码以找出为什么 params["lines-width"] 为负数,我建议 Raphael 防止这种情况:https://github.com/DmitryBaranovskiy/raphael/issues/623

关于javascript - 拉斐尔的不透明度超出范围(负值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12606455/

相关文章:

javascript - wavesurfer getPeaks 返回一个空数组

javascript - 设置数组来处理大小条件

javascript - 保存输入字段 Chrome 扩展程序

javascript - 代码中的 '2e4'是什么意思

javascript - 获取矩形以使用 Raphael 和 Handdrawn.js 填充 svg

python - 在字典和 numpy 数组中查找最大值的性能

matlab - 如何在 MATLAB 中找到多维矩阵的最大值或最小值?

javascript - 如何在类库项目中启用Jscript智能感知(VS2010)

javascript - 是闭合路径内的点 - SVG Javascript

algorithm - 查找 min(max(A[L], A[L+1],...,A[R]), min(B[L], B[L+1],..., B[R] 的有效方法))