[英]print media query not working on iOS(chrome, safari, mozilla)
I'm trying to figure why the @media print
doesn't seem to work on the iOS, on android the functionality works fine. 我试图弄清楚为什么
@media print
似乎不适用于iOS,在Android上功能正常。 Basically I've made a functionality to hide the contents that aren't part of the print 基本上我已经创建了一个隐藏不属于打印内容的功能
body.printing *{display : none}
and only display the contents that will be printed 并且仅显示将要打印的内容
body.printing .print-me, body.printing .print-me > div{display : block}
. body.printing .print-me, body.printing .print-me > div{display : block}
。
$('.print-modal').on('click', function() {
$('body').addClass('printing');
window.print();
$("body").removeClass("printing");
})
@media print {
/* Hide everything in the body when printing... */
body.printing * { display: none; }
/* ...except our special div. */
body.printing .print-me, body.printing .print-me > div { display: block; }
}
@media screen {
/* Hide the special layer from the screen. */
.print-me { display: none; }
}
Maybe the issue is, you are adding a class printing
and removing the same class immediately. 也许问题是,您正在添加类
printing
并立即删除相同的类。 That's could be the reason. 这可能是原因。
Try changing the logic. 尝试更改逻辑。 You don't need to add a class for printing.
您无需为打印添加类。 Instead use print media query
@media print
to handle print logic. 而是使用打印介质查询
@media print
来处理打印逻辑。
$('.print-modal').on('click', function() {
window.print();
})
@media print {
/* Hide everything in the body when printing... */
body * { display: none; }
/* ...except our special div. */
body .print-me, body .print-me > div { display: block; }
}
@media screen {
/* Hide the special layer from the screen. */
.print-me { display: none; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.