使Firefox SDK面板适合各种外观
Making Firefox SDK panel fit on every apperance
我正在使用SDK编写Firefox扩展,并且在制作合适大小的弹出窗口时遇到麻烦。我正在使用MDN和SO的示例来制作类似于MDN页面中该部分所示的示例的东西。
我做的面板是有点小的第一次打开(它垂直滚动),但我更困惑的变化高度每次打开
我的面板有这样的HTML代码:
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<ul id="links">
<li id="menu1">Menu1 text</li>
<li id="menu2">Menu2 text</li>
<li id="menu3">Menu3 text</li>
</ul>
</body>
</html>
在我的index.js
中,我创建了如下面板:
var button = ToggleButton({
id: "name-of-extension",
label: "Label text",
icon: './icon.svg',
onChange: handleToggleButton
});
var button_panel = Panel({
contentURL: './popup_interface.html',
contentScriptFile: ['./script-for-onclicks.js', './windowsize.js'],
onHide: handleHidePanel,
onShow: function() {
button_panel.port.emit('fetchwinsize');
}
});
button_panel.port.on('winsize', function(data) {
console.log(data);
button_panel.resize(data.width, data.height);
});
function handleToggleButton(state) {
if (state.checked) {
button_panel.show({
position: button
});
} else {
button_panel.hide();
handleHidePanel();
}
}
function handleHidePanel() {
button.state("window", {checked: false});
}
其中windowsize.js
有以下内容:
self.port.on('fetchwinsize', function() {
let listElement = document.getElementById("links");
self.port.emit("winsize", {height: listElement.scrollHeight, width: listElement.scrollWidth});
});
反复打开面板(通过点击切换按钮)会以我不理解的方式改变尺寸:
JPM [info] Creating a new profile
console.log: vanir: {"height":48,"width":304}
console.log: vanir: {"height":48,"width":272}
console.log: vanir: {"height":48,"width":240}
console.log: vanir: {"height":48,"width":208}
console.log: vanir: {"height":64,"width":176}
console.log: vanir: {"height":64,"width":144}
console.log: vanir: {"height":96,"width":129}
在此之后,尺寸保持在96x129不变,需要水平和垂直滚动(尽管文字换行会导致垂直滚动)。
我给William Bamberg发了一封电子邮件以获取MDN示例的源代码,他意识到了这个问题。
如果有人也试图这样做,问题是面板的总大小(包括填充和边距)被设置为列表元素的大小,这会每次挤压列表元素。
修复这是一个相对简单的CSS更改:
html, body, ul {
margin: 0;
padding: 0;
list-style: none;
}
ul {
display: inline-block;
}
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- JS可以在Chrome中工作,但不能在Firefox中工作
- createElement("a") - FireFox JavaScript
- 为什么javascript:void(0)在Firefox中不起作用
- Facebook登录按钮没有'不能在Firefox上工作
- jpm的默认Firefox路径没有'不起作用
- FF和Chromium中CSS样式按钮的外观差异
- jQuery Facebox插件:关注弹出的外观
- 重载JS'firefox中的对象原型
- Ajax调用在Firefox中不会自动响应
- JS在firefox中无法正常工作
- firefox插件和dev/panel之间的通信
- IE/Chrome中未定义的函数,但Firefox中没有
- ascii输入键通过firefox中的javascript返回0
- 在firefox和chrome中的左侧显示iframe滚动条
- html5 drawImage适用于firefox,而不是chrome
- angularjs$valid-on-dates在firefox中报告错误
- 您可以使用JavaScript和Firefox扩展来更改现有页面吗
- 制作Firefox'其原生全屏外观类似于Chrome's
- 使Firefox SDK面板适合各种外观