如何调整Firefox Add-on SDK弹出/面板的大小? Firefox Add-on SDK弹出/面板太小

时间:2016-07-07 23:37:22

标签: css popup firefox-addon firefox-addon-sdk

我在Firefox中关注tutorial on creating a popup for an add-on,效果很好。

我现在遇到的问题是它创建的弹出窗口不会改变大小以适应我添加的内容。相反,它会添加滚动条。

那么,如何更改Firefox Add-on SDK弹出窗口的大小以显示所有内容?

2 个答案:

答案 0 :(得分:1)

你必须自己处理。

如果您在创建面板时已经知道所需的尺寸,则可以将heightwidth作为对象的属性传递给Panel()构造函数。

创建面板后,可以通过在其上设置heightwidth属性来更改其大小。

heightwidth值是以像素为单位的数字。

有关如何使用面板的完整文档,请参阅https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/panel

答案 1 :(得分:1)

虽然教程和文档从未说过,但面板的高度和宽度始终默认为相同的小尺寸。

要更改它,您可以使用height and width parameters for the panel class

如果您希望它自动更改,您可以使用以下代码:

//index.js
var panel = require("sdk/panel").Panel({
    height: 200,  //choose your default
    width: 200,
    contentURL: data.url("popup.html"),
    contentScriptFile: data.url("auto_resize_popup.js")
});

panel.port.on("resize", function (size) {
    console.log(size);
    panel.resize(size.width, size.height);
});

...

//auto_resize_popup.js

    var content = document.body;
    var size = {};
    size.width = content.offsetWidth + 2;  //2 extra pixels get rid of scroll bars
    size.height = content.offsetHeight + 2;
    self.port.emit("resize", size);
相关问题