javascript - 将固定/粘性标题注入任何网页
问题描述
我想将一个粘性/固定标题注入用户在我的 Chrome 扩展程序中加载的任何网页。
使用JQuery
我可以插入一个 div 并设置它的样式。我尝试使用教程中为粘性标题指定的几种不同样式,但它与页面重叠,而不是将页面进一步向下推。
如果我正在编写网页,则处理此问题会很好,但在这种情况下,网页可以包含任何 html 或 css。
这是我尝试过的一个例子。
$(function () {
$("body").prepend(
"<div id='my-header'>This is displayed at the top of the page</div>'"
);
$("#my-header").css({
"z-index": 2000,
overflow: "hidden",
"background-color": "#333",
position: "fixed",
top: 0,
width: "100%",
height: "200px",
});
});
实现这一目标的正确方法是什么?
解决方案
推荐阅读
- python - 如何通过python for循环创建100个数据框名称
- windows - Qt QProcess 无法在可在 cmd 提示符下运行的命令上启动
- c++ - 来自空括号的不明确复制分配的编译器差异
- python - 根据熊猫中不同长度的字符串结尾创建新列
- android - 应用 Android 与 google photo-google drive 关联
- git - 如何使用 Git 客户端和 git 服务器配置无密码身份验证?
- opencv - OCR 风玫瑰中的书面角度
- html - 输入类型范围限制为仅抓取句柄
- r - 我如何使用 colnames 作为chart.Correlation 的标签,如 corrplot
- jquery - 使用jquery单击其他按钮时如何显示模态但不中断光标