Javascript 书签可以覆盖网页上的图像吗?
可以使用书签在网页上覆盖图像吗?不是作为弹出窗口,而是作为由 CSS 定位的图像,并具有高 z-index 以显示在其他元素之上。并且没有遮罩即 Shadowbox 或类似的 jQuery 效果。只是来自 URL 的图像,位于浏览器窗口的左下角。
这是我到目前为止所拥有的,但这可能是错误的方向:
javascript:(function(){document.write("<style type='text/css'>body {background-image:url(http://example.com/image.png); position: absolute; left:50px; top:300px; z-index:9999;}</style>");})()
我有一个 JS 函数,它作为书签来更改页面上文本的大小写,现在我希望能够显示使用小书签时的图像。
Can a bookmarklet be used to overlay an image on a web page? Not as a pop-up, but as a image positioned by CSS and with a high z-index to display on top of other elements. And without a mask i.e., Shadowbox or similar jQuery effect. Just an image from a URL and positioned in the bottom left hand corner of the browser window.
This is what I have so far, but it may be the wrong direction to be going:
javascript:(function(){document.write("<style type='text/css'>body {background-image:url(http://example.com/image.png); position: absolute; left:50px; top:300px; z-index:9999;}</style>");})()
I have a JS function that works as a bookmarklet to change the case of text on the page, and now I'd like to be able to show an image when the bookmarklet is used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望图像覆盖页面,为正文设置背景图像将无济于事。另外,
document.write
不能直接用于添加CSS样式。您可能想要做的是向页面添加一个新的
img
元素,并为其指定absolute
或fixed
定位,以及较高的 <代码>z-index。以下是使用
固定
定位将 SO 徽标添加到窗口一角的示例:Setting a background image for the body won't help if you want the image to overlay the page. Also,
document.write
can't be used directly to add CSS styles.What you probably want to do is add a new
img
element to the page, and give itabsolute
orfixed
positioning, along with a highz-index
.Here's an example that adds the SO logo to the corner of the window, using
fixed
positioning:我认为 document.write 在这里不合适;为什么不创建一个新的 img 元素并将其附加到正文中?
i don't think document.write would be appropriate here; why not create a new img element and append it to the body?