html2canvas(document.querySelector('#index'),{ dpi: window.devicePixelRatio * 2 }).then(function(canvas) { document.querySelector(".canvas").setAttribute('src',canvas.toDataURL()); $("#index").hide(); $(".canvas").show(); });
<img class="canvas" src="" > <div class="award_img" id="index"></div>
// js引入代码 <script type="text/javascript" src="https://blog-static.cnblogs.com/files/gongxiaoyan/jquery-3.4.1.min.js"></script> <script type="text/javascript" src="https://blog-static.cnblogs.com/files/gongxiaoyan/html2canvas.js"></script>