繁体   English   中英

获取伪元素的背景样式

[英]Get the background styles of a pseudo element

Internet Explorer 8不允许打印背景图像。
不幸的是,我被要求做这项工作。

在一些必须可打印的伪元素中存在“重要”图像。
我认为有可能将这些背景图像转换为<img/>元素,但似乎无法在Internet Explorer 8中读取伪元素的样式,因为它不支持getComputedStyle

有什么好主意吗?

有关:
https://developer.mozilla.org/en/docs/Web/API/window.getComputedStyle
http://caniuse.com/getcomputedstyle/embed
SO“获取伪元素样式值”

这应该工作:

var img = window.getComputedStyle(
    document.querySelector('.element'), ':before'
).getPropertyValue('background');

编辑 :我有一个不使用querySelector工作小提琴

var img = window.getComputedStyle(
    $(".element")[0], ':before'
).getPropertyValue('background');

基本上,您只想在getComputedStyle获取元素作为第一个参数;

但是仍然没有修复IE 8的要求,因为getComputedStyle不支持getComputedStyle ,但是...... 这个问题可能会提供答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM