2012-07-24 153 views
0

我是歌剧扩展开发的初学者。Opera扩展中的覆盖

是否有相当于firefox xul在歌剧中的覆盖?

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

+0

我觉得你有与歌剧HTML做到这一点。但是,无论如何,请查看http://dev.opera.com/articles/view/opera-extensions-buttons-badges-and-popups/ – c69 2012-08-07 21:28:45

回答

0

要与特定页面交互,您需要使用注入脚本。这是放置在名为includes的文件夹内的JavaScript文件(实际为UserScript/UserJS)。

在这个文件中,您可以将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);