前端截图

前端截图

前言

就是用html2canvas.min.js来实现前端页面截图

代码

function generateCanvas(){
    var test = $(".bg_wrap").get(0); //将jQuery对象转换为dom对象
    // 点击转成canvas
    html2canvas(test).then(function(canvas) {
        // canvas宽度
        var canvasWidth = canvas.width;
        // canvas高度
        var canvasHeight = canvas.height;
        // 渲染canvas
//      $('.cavs').after(canvas);
        /*
         * 注,如果截图中的图片和当前页面不是一个域名,存在跨域问题,会导致 图片地方空白
         */
        var img = canvas.toDataURL("image/png");
        var newimg = img.split(",")[1];
        console.log("img",img)
    });
}

 

插件

📎html2canvas.min.js

posted @ 2022-01-11 15:46  lvqs  阅读(259)  评论(0编辑  收藏  举报