遇到遍历整个数组的循环问题,而不仅仅是找到正确的数字并停止。
如果代码看到(curOpacity)为100,则应输出61。它将输出12。对于高于12的任何值也是如此。我可以看到在12的数组中,等于12的值停止循环。
它正在Illustrator中运行。
我曾经尝试做一个反向循环,但这似乎也不起作用。
function opacitychange()
{
var docRef = app.activeDocument;
var layers = docRef.layers;
var paths = docRef.pathItems;
var pathLen = paths.length;
var opacityRelationships = {
"100": 61,"99": 61,"98": 61,"97": 60,"96": 60,"95": 59,"94": 59,"93": 58,"92": 57,"91": 57,"90": 57,"89": 56,"88": 56,"87": 56,"86": 55,"85": 55,"84": 55,"83": 54,"82": 54,"81": 54,"80": 53,"79": 53,"78": 53,"77": 52,"76": 52,"75": 52,"74": 51,"73": 51,"72": 50,"71": 50,"70": 49,"69": 49,"68": 48,"67": 48,"66": 47,"65": 47,"64": 46,"63": 46,"62": 45,"61": 45,"60": 44,"59": 43,"58": 42,"57": 41,"56": 40,"55": 39,"54": 38,"53": 37,"52": 36,"51": 35,"50": 34,"49": 34,"48": 34,"47": 33,"46": 33,"45": 33,"44": 32,"43": 32,"42": 31,"41": 31,"40": 30,"39": 30,"38": 29,"37": 29,"36": 28,"35": 27,"34": 27,"33": 26,"32": 26,"31": 25,"30": 25,"29": 24,"28": 23,"27": 22,"26": 21,"25": 20,"24": 19,"23": 18,"22": 17,"21": 16,"20": 15,"19": 15,"18": 14,"17": 14,"16": 13,"15": 13,"14": 12,"13": 12,"12": 12,"11": 11,"10": 10,"9": 9,"8": 8,"7": 7,"6": 6,"5": 5,"4": 4,"3": 3,"2": 2,"1": 1,"0": 0
}
function updateOpacityGradient(item)
{
var stops = item.fillColor.gradient.gradientStops;
var curOpacity;
for (var x = 0, len = stops.length; x < len; x++)
{
curOpacity = Math.floor(stops[x].opacity);
stops[x].opacity = opacityRelationships[curOpacity];
}
}
for (var i = 0; i < pathLen; i++)
{
if (paths[i].filled && paths[i].fillColor == "[GradientColor]")
{
updateOpacityGradient(paths[i]);
}
}
}opacitychange();