问题 在Firefox扩展中复制Google Chrome浏览器操作弹出效果


Chrome浏览器操作默认提供非常好的弹出效果。

删除了死ImageShack图像链接

  • 将鼠标悬停在工具栏图标上可提供整洁的悬停效果。

  • 单击工具栏图标会显示一个很好的动画,可以打开弹出的html文件。

  • 弹出窗口与按下的按钮对齐。

  • 再次单击工具栏图标会淡出弹出窗口。

有关如何使用Firefox扩展来估算此效果的任何想法?有没有人成功地取得了类似这种效果的东西?

谢谢。


9982
2018-01-16 00:40


起源

我已经发布了Jetpack模块,带来了 chrome.browserAction Firefox的API和外观,请参阅 这个答案 用于演示。 - Rob W


答案:


对于刚开始使用您的第一个Firefox扩展的人来说,就像我在这里做的那样是一个示例代码:

yourextname \铬\内容\ browser.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://yourextname/skin/toolbar.css" type="text/css"?>

<overlay id="yourextname_overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <popupset>
        <menupopup id="yourextname_menu_popup">
            <menuitem label="Website" oncommand="gBrowser.selectedTab = gBrowser.addTab('http://www.your-website.com/');" />
            <menuseparator />
            <menuitem label="Options" oncommand="window.open('chrome://yourextname/content/options.xul', 'Options', 'dialog,chrome,modal,titlebar,toolbar,centerscreen=yes');" />
        </menupopup>

        <panel id="yourextname_popup" noautohide="false" noautofocus="true">
            <label control="vvvname" value="Name:"/><textbox id="vvvname"/>
        </panel>
    </popupset>

    <toolbarpalette id="BrowserToolbarPalette">
        <toolbarbutton id="yourextname_toolbar_button" class="toolbarbutton-1" context="yourextname_menu_popup" oncommand="document.getElementById('yourextname_popup').openPopup(document.getElementById('yourextname_toolbar_button'), 'after_start', 0, 0, false, false);" label="button name" tooltiptext="tooltip" />
    </toolbarpalette>
</overlay>

yourextname \皮肤\ toolbar.css
这会在工具栏按钮上添加图标:

#yourextname_toolbar_button {
    list-style-image:url(chrome://yourextname/skin/icon_024.png);
}

toolbar[iconsize="small"] #yourextname_toolbar_button {
    list-style-image:url(chrome://yourextname/skin/icon_016.png);
}

yourextname \ chrome.manifest用于

content yourextname chrome/content/
overlay chrome://browser/content/browser.xul chrome://yourextname/content/overlay.xul

skin    yourextname classic/1.0 skin/
style   chrome://global/content/customizeToolbar.xul chrome://yourextname/skin/toolbar.css

注意:请确保将所有“yourextname”字符串替换为唯一的,最好用您的扩展名替换。


7
2018-05-25 09:34





如果有人正在研究这个并试图找到答案,最终使用browser.xul文件中的toolbarpalette中的面板对我来说效果很好。


4
2018-01-27 20:50



我试图找到这个问题的答案。与Chrome相比,Firefox扩展似乎是一个巨大的痛苦。 - cnanney
谢谢克里斯。对于我们这些开始使用FF的人,你能展示一些演示代码吗?干杯。 - mikemaccana
演示会很好 - Artjom Zabelin