简体   繁体   English

如何使用javascript打印可滚动的div内容?

[英]How to print scrollable div content using javascript?

I have tried multiple different avenues on trying to get this to work and when rendering the print media query using dev tools I get a scrollable div but when printing I just get 1 page.我尝试了多种不同的途径来尝试使其工作,并且在使用开发工具呈现打印媒体查询时,我得到了一个可滚动的 div,但在打印时我只得到了 1 页。 I've attached my css below.我在下面附上了我的css。

  body * {
    visibility: hidden;
    overflow-y: auto;
  }
  #print,
  #print * {
    visibility: visible;
  }
  #print {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
  }

Your question is very general, and I'm not going to try to answer you, however I will tell you how to try to solve it yourself.你的问题很笼统,我不打算回答你,但是我会告诉你如何尝试自己解决。

Using Chrome's dev tools, it is possible to see how the page would look like when printed.使用 Chrome 的开发工具,可以查看页面打印时的样子。 Press F12 to open dev tools, then under Rendering find the Emulate CSS media type and select print - then you can play around with styles on the Elements page and see how that would translate to a printed version.按 F12 打开开发工具,然后在“ Rendering下找到“ Emulate CSS media type并选择“ print - 然后您可以在“ Elements页面上使用样式并查看如何将其转换为打印版本。

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

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