次のようなイメージ タグと少しの jQuery を持つ HTML があります。
<body>
<img id="MainImage" src="../img/MainImage.png" style="position: absolute;">
<script type="text/javascript">
$(document).ready(function() {
var $img = $("#MainImage");
$img.hide();
$('div').mousemove(function(e) {
if ($(this).attr('align') === 'center') {
// only show if the align attribute has value center
$img.fadeIn(0);
$img.offset({
top: e.pageY - $img.outerHeight()-2,
left: e.pageX - ($img.outerWidth()-18)
});
}
}).mouseleave(function() {
$img.fadeOut(250);
});
</script>
</body>
次のコードを含むこのマニフェスト ファイルもあります。
{
"name": "Div Image Test",
"version": "1.0",
"manifest_version": 2,
"permissions": [
"tabs", "http://*/*"
],
"content_scripts": [{
"matches": ["http://*/*"],
"js": ["js/CoreTest.html"],
"run_at": "document_end"
}]
}
このスクリプト/拡張機能の目的は、ユーザーが任意の div (HTML 属性「align='center'」を使用) にカーソルを合わせるたびに、マウス カーソルの横に画像がポップアップすることです...これは既に機能していますが、必要なもの拡張機能のインストール時に、すべての Web ページの「body」タグにスクリプト/HTML ファイルを挿入します。
どうすればこれを達成できますか?
前もって感謝します。