【问题标题】:Overlays in Opera ExtensionsOpera 扩展中的覆盖
【发布时间】:2012-07-23 08:46:01
【问题描述】:

我是Opera扩展开发的初学者。

opera 中是否有对应的 firefox xul 覆盖?

当我将鼠标悬停在文本上时,我想创建临时叠加层。当鼠标离开文本时,覆盖应该改变或消失。

【问题讨论】:

标签: overlay opera opera-extension


【解决方案1】:

要与特定页面交互,您需要使用注入脚本。这是一个 JavaScript 文件(实际上是 UserScript/UserJS),位于名为 includes 的文件夹中。

在此文件中,您可以为纯 CSS 工具提示添加代码,例如在此处找到的代码:http://sixrevisions.com/css/css-only-tooltips/,然后将 CSS 附加到页面中的样式元素。

这个例子应该给你一些基础:

// includes/injected.js
window.addEventListener('DOMContentLoaded', function() {
    // Set the CSS for the tooltip
    var tooltipCSS = '.tooltip {position: relative;}.tooltip span {margin-left: -999em; position: absolute;} .tooltip:hover span {border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); position: absolute; left: 1em; top: 2em; z-index: 99; margin-left: 0; width: 250px;} .classic {padding: 0.8em 1em;} * html a:hover {background: transparent;} .classic {background: #FFFFAA; border: 1px solid #FFAD33; color: #333333;}';

    // Set the text for the tooltip
    var tooltipText = 'This is a tooltip';

    // Add the CSS to the page
    var style = document.createElement('style');
    style.textContent = tooltipCSS;
    document.head.appendChild(style);

    // Loop through all links to add "tooltip" class and extra <span>
    var links = document.getElementsByTagName('a');
    for (var i = 0, len = links.length; i < len; i++) {
        links[i].classList.add('tooltip');
        links[i].innerHTML += '<span class="classic">' + tooltipText + '</span>';
    }
}, false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多