canvas截取部分图片

canvas截取部分图片

<div id="firstPhoto">
    <h1>测试图片哈哈</h1>
</div>
<img src="" id="picture">
<script type="text/javascript" src="layui/jquery.min.js"></script>
<script type="text/javascript" src="html2canvas.min.js"></script>
<script>
    let element = document.querySelector("#firstPhoto");
    let imgWidth = element.offsetWidth;
    let imgHeight = element.offsetHeight;
    window.pageYOffset = 0;
    document.body.scrollTop = document.documentElement.scrollTop = 0;
    let configObj = {allowTaint:true,imageTimeout:2000000};
    html2canvas(element, configObj).then((canvas) => {
        let imgUrl = canvas.toDataURL("image/jpeg");
        $('#picture').attr('src',imgUrl);
        $('#firstPhoto').remove();
    });
</script>

下载地址:https://files.cnblogs.com/files/lyt520/html2canvas.min.js

标签:

相关文章

发表评论