有没有办法通过使用min-width / max-width CSS属性或其他方式为使用Dialog API打开的对话框设置常量? API仅允许设置宽度和高度百分比,这使得在调整大小或使用不同分辨率时框看起来不一致(1024px的30%是一个瘦的窗口,但是对于1920来说看起来很好)。
我注意到弹出的“Office加载项”存储似乎有一个最小宽度/最大宽度,因此在调整大小时保持一致的外观,我希望我可以利用它的功能同样。
答案 0 :(得分:0)
office-js-helpers库有一个Dialog API的包装器,可以让你设置尺寸,以像素为单位。可能值得尝试。
编辑: 如果帮助者没有帮助,我建议您转到Office Developer Voice并投票赞成此建议:Improve Custom Dialog
或创建自己的。
答案 1 :(得分:0)
您在这里:
var dim = pixelToPercentage(700, 350);
Office.context.ui.displayDialogAsync(window.location.origin + "/pop-ups/create_export_link.html",
{ height: dim.height, width: dim.width },
createExportLinkCallback);
,支持功能为:
function pixelToPercentage(heightInPixel, widthInPixel) {
var height = Math.floor(100 * heightInPixel / screen.height);
var width = Math.floor(100 * widthInPixel / screen.width);
return { height: height, width: width };
}
这样,您可以以百分比格式动态计算尺寸。
答案 2 :(得分:0)
基于 Alaa 的回答,这对我来说效果更好(在 pixelToPercentage 函数中)以支持 Web 和桌面:
var cheight = window.height? window.height : screen.height;
var cwidth = window.height? window.width : screen.width;
if (heightInPixel > cheight) heightInPixel = cheight;
if (widthInPixel > cwidth) widthInPixel = cwidth;
var height = Math.floor(100 * heightInPixel / cheight);
var width = Math.floor(100 * widthInPixel / cwidth);