JS 列印介面的CSS置中代碼適用所有瀏覽器_javascript技巧

來源:互聯網
上載者:User
複製代碼 代碼如下:

function preview(oper) {
if (oper < 10) {
bdhtml = window.document.body.innerHTML;//擷取當前頁的html代碼
sprnstr = "<!--startprint" + oper + "-->";//設定列印開始地區
eprnstr = "<!--endprint" + oper + "-->";//設定列印結束地區
prnhtml = bdhtml.substring(bdhtml.indexOf(sprnstr) + 18); //從開始代碼向後取html

prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));//從結束代碼向前取html
window.document.body.innerHTML = prnhtml;
window.print();
window.document.body.innerHTML = bdhtml;
} else {
window.print();
}

}
#outer {
display:table;
height:400px;
#position:relative;
overflow:hidden;
}
#middle {
display:table-cell;
vertical-align:middle;
#position:absolute;
#top:50%;
}
#inner {
#position:relative;
#top:-50%;
}



<div id=”outer”>
<div id=”middle”>
<div id=”inner”>
<!–這裡是要垂直置中的內容–>
</div>
</div>
</div>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.