1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>页面转图片</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <script src="https://cdn.bootcss.com/html2canvas/0.4.1/html2canvas.js"></script> <style type="text/css"> .modal-body canvas{ width: 100%; box-shadow: 0 0 12px #d1d1d1; } </style> </head> <body> <button id="save" type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl">点击生成图片</button> <div id="to-img" style="background-color: #f9eeee;"> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> <h2>页面转图片的内容</h2> </div> <div class="modal fade bd-example-modal-xl" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-xl modal-dialog-scrollable" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">页面转图片:</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Save</button> </div> </div> </div> </div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> <script> document.querySelector("#save").onclick=function(event) { html2canvas(document.querySelector("#to-img"),{ onrendered: function(canvas) { document.querySelector(".modal-body").appendChild(canvas);
} }) }; </script> </body> </html>
|