简体   繁体   English

如何在jQuery中更改CSS“ @media print”样式?

[英]How can I change CSS '@media print' styles in jQuery?

I am dynamically setting the offset of an html element where position: relative . 我正在动态设置html元素的偏移量,其中position: relative I use the following code (in pure js but jQuery is ideal for me): 我使用以下代码(在纯js中,但jQuery非常适合我):

document.querySelector('#overlay-marker-report').style.left = Math.floor(cli.getXLocation(period)) + 134 + "px";

For print, this offset has to change or things don't align properly. 对于打印,此偏移量必须更改,否则可能无法正确对齐。 Is there a way to do what I am doing but for print specifically? 除了专门用于印刷,是否有办法做我正在做的事情?

You can try using matchMedia . 您可以尝试使用matchMedia If that doesn't suite your needs you can change some CSS property on #overlay-marker-report (eg float) and test if @media is print that way. 如果这不能满足您的需求,则可以在#overlay-marker-report(例如float)上更改一些CSS属性,并测试@media是否以这种方式打印。

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

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