window.print()打印照片,无需滚动条所有内容的div [英] window.print() print all div content without scrollbar

查看:265
本文介绍了window.print()打印照片,无需滚动条所有内容的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印网页用javascript函数 window.print()

i want to print web page with javascript function window.print()

该页面包括用滚动条的div

the page include div with scroll bar

但显示只打印出的div的一部分

But printing is displayed only part of the div

我试图添加到CSS

@media print
{
 .myDiv
  { 
    height:100%;
  }

}

但它不能正常工作,

but it not work,

我要显示没有滚动条所有内容的div
我该怎么办呢?

i want to show all div content without scroll bar how i do it?

推荐答案

这个方法会让您的打印任意分区。

This method will let you print any arbitrary div.

使用jQuery:

function print(selector) {
    var $print = $(selector)
        .clone()
        .addClass('print')
        .prependTo('body');

    //window.print() stops JS execution
    window.print();

    //Remove div once printed
    $print.remove();
}

和一些CSS:

body, html {
    width: 100%;
    height: 100%;
}

.print {
     position: fixed;
     overflow: auto;
     width: 100%;
     height: 100%;
     z-index: 100000; /* CSS doesn't support infinity */

     /* Any other Print Properties */
}

这篇关于window.print()打印照片,无需滚动条所有内容的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆