我有一个页面抛出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]时,该代码的最后一行如何不透明== -0.23185589076263113?

(raphael.js中的N.B. mmax是math.max,mmin是math.min。)

最佳答案

找到了。

width && width < 1 && (opacity *= width) && (stroke.weight = 1);


如果宽度为负(在这种情况下为负),则将打破不透明度范围。宽度是在我引用的块之前的行上设置的(5139):

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


我需要调试代码以找出params [“ stroke-width”]为何为负,我建议Raphael对此进行防范:https://github.com/DmitryBaranovskiy/raphael/issues/623

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

10-12 14:08