首页 > 解决方案 > 当 true 忽略其他所有内容时,Javascript 多个 if 停止

问题描述

我有 25 个 IF 语句,它们查看图像并根据其大小和与 Photoshop 中的文档大小(画布)相关的位置执行不同的功能。

我发现当脚本执行 if 为 true 时,它​​不会继续向下堆栈并执行其他 true if。

这是javascript的副产品,还是我的错误?

例如,这两个 if 都为真,但它只执行第一个。如果我再次运行该脚本,它将执行第二个 if。但我想弄清楚如何让脚本运行所有如果,即使一个是真的。


//bottom edge only off doc
if (layerSmaller && layerLeftIn && layerRightIn && layerTopIn && layerBottomOut) {
    activeDocument.activeLayer.translate(0,docHeight-layerBottom+2);
    var percentageChange = ((docHeight / layerHeight) * 101);
    resizeBCenter(percentageChange) 
}

//layer smaller horizontally and right more than 65
if (layerWidth <= docWidth && layerTopOut && layerBottomOut && layerLeftOut && layerRightIn && Rmargin >= 65) {
   var percentageChange = ((docWidth / layerWidth) * 101);
resizeTLeft(percentageChange) 
  app.activeDocument.selection.selectAll();
  align('AdCH');
  align('AdCV');
  app.activeDocument.selection.deselect();
}

这可以做到吗?

标签: javascriptphotoshop

解决方案


推荐阅读