html2canvas图片保存空白解决
2020/09/01    标签: html2canvas    html2canvas截图空白   
            $("#Panel_News").prepend($("#news_title").css('textAlign', 'center'));
            $("#Panel_News td").each(function(){
                if($(this).children().length===0){
                    $(this).text($.trim($(this).text()));
                }
            });
            $("#Panel_News td").css({
                'border-collapse': 'collapse',
                'border-spacing':0,
                'line-height':'28px',
                'font-size':'14px'
            })
        $(window).scrollTop($("#Panel_News").offset().top + $("#Panel_News").outerHeight()-$(window).height());//重要
        $('html,body').css('overflow', 'hidden');//重要
        html2canvas(document.querySelector("#Panel_News"),{
            useCORS:true,//保证跨域图片的加载
            // width: $("#Panel_News").outerWidth(),
            // height:$("#Panel_News").outerHeight(),
            // windowWidth:document.body.scrollWidth,
            // windowHeight:document.body.scrollHeight,
            // x:$(window).scrollTop(),
            y: $("#Panel_News").offset().top
        }).then(canvas => {
            var downLoadDom = $("<a download='"+new Date().toLocaleString()+"价格' href='" + canvas.toDataURL("image/png", 0.8) + "'></a>");
            $("body").append(downLoadDom)
            downLoadDom[0].click();
            $('html,body').css('overflow', '');//重要
            //console.log(canvas.toDataURL)
        })