在 photoshop 对话框中将 Javascript 函数参数与 onClick 一起使用不起作用
Using Javascript function parameters with onClick in photoshop dialog not working
我这里有这个脚本(很多,对不起):
var dlg = new Window('dialog', 'Templates',[1100,540,1465,720]);
dlg.btnPnl = dlg.add('panel', [20,15,345,155], 'Please select your template:');
dlg.btnPnl.Shoes = dlg.btnPnl.add('button', [20,55,300,45], 'Shoes, Hats and Belts', {name:'ok'});
dlg.btnPnl.Bags = dlg.btnPnl.add('button', [20,85,300,45], 'Bags and Pouches', {name:'ok'});
dlg.btnPnl.Shoes.onClick = extendCanvas(0.035, 1.035)
dlg.btnPnl.Bags.onClick = extendCanvas(0.221, 1.221)
dlg.show();
function extendCanvas(negative, positive) {
#target photoshop
var doc = activeDocument;
var docWidth = activeDocument.width;
var docHeight = activeDocument.height;
var docName = activeDocument.name;
var guides = activeDocument.guides;
// If width is longer than height, extend height
if(docHeight/ docWidth < 1.044) {
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
var stepOne = docWidth * 1.044;
var stepTwo = stepOne * negative; // NEGATIVE
var stepThree = stepOne - stepTwo;
var newHeight = stepThree
doc.resizeCanvas(null, UnitValue(stepThree, "px"), AnchorPosition.BOTTOMCENTER)
doc.guides.add(Direction.HORIZONTAL, stepThree)
doc.resizeCanvas(null, UnitValue(stepOne, "px"), AnchorPosition.TOPCENTER)
doAction('[White Layer & Move]','Line Action')
// If height is longer than width, extend width
} else if(docWidth/docHeight < 0.957) {
app.preferences.rulerUnits = Units.PIXELS
toSubtract = docHeight * negative; // NEGATIVE
newHeight = docHeight - toSubtract;
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
doc.resizeCanvas(UnitValue(docHeight * 0.957, "px"), null, AnchorPosition.BOTTOMCENTER)
doc.guides.add(Direction.HORIZONTAL, docHeight)
var docWidth = doc.width;
var newHeight = docHeight * positive; //POSITIVE
var newWidth = docWidth * positive; //POSITIVE
doc.resizeCanvas(UnitValue(newWidth, "px"), null, AnchorPosition.TOPCENTER)
doc.resizeCanvas(null, UnitValue(newHeight, "px"), AnchorPosition.TOPCENTER)
doAction('[White Layer & Move]','Line Action')
}
dlg.close();
}
当我没有只有一个函数 extendCanvas 及其参数,而是有两个单独的函数用于鞋子和包包并且每个 onClick 调用它们时,它的效果很好。但是出于某种原因,当我将它们合并为一个并在 onClick 中向函数添加参数时,当我运行脚本时,它只是完全忽略 dlg(它不显示)而只是运行函数(也是不正确的,因为最终画布大小略有偏差)。
我完全感到困惑,非常感谢一些帮助。
提前感谢!
像这样添加点击处理程序:
dlg.btnPnl.Shoes.onClick = function() {extendCanvas(0.035, 1.035);};
相关文章:
- onClick和onClientClick事件一起使用.在Internet Explorer中不起作用
- 如何找到元素'的onClick处理程序实际上是与jQuery一起添加的
- onclick 和 ondblclick 不能一起工作
- 数据切换和onclick不能一起工作,我太新了,无法应用@epascarello的解决方案
- JSF:一起使用 onclick + actionListener
- onclick事件与ulli一起启动一个函数
- 当文本与元素一起悬停时发生更改时,onclick事件的Grab Text
- 我可以/如何将OnClick与中的if语句一起使用
- onclick事件仅适用于按钮,而不适用于与按钮一起使用的glyphicon
- 如何将 onclick 与文本区域一起使用
- 如何在angularjs中将HTML和onclick函数一起插入视图
- Onclick不能与bootstrap一起正常工作
- Rails link_to和onClick与target=_blank不能一起工作
- 为什么.ajax()不能与onclick一起工作?
- 使onclick功能与ENTER一起工作;Go"Safari Mobile(iOS)上的按钮
- Asp.net OnClick事件和OnClientClick事件一起使用
- onClick事件与被单击的元素一起被父元素捕获
- onclick和href一起不起作用
- setTimeout不能与onclick一起工作
- 在 photoshop 对话框中将 Javascript 函数参数与 onClick 一起使用不起作用