当页面出现滚动条时,会出现截图空白,即截图有偏移

百度了很多解决方案,但是都不行。一次偶然看到一位大佬的试了一下可以,但是我再往回找找不到那个大佬的文章了,如果大佬看到,觉得冒犯了可联系我删除。

npm install html2canvas --save

import html2canvas from "html2canvas";

 let myBox = this.$refs.saveBox;
      html2canvas(myBox, {
        useCORS: true,
        width: window.screen.availWidth,
        height: window.screen.availHeight,
        windowWidth: document.body.scrollWidth,
        windowHeight: document.body.scrollHeight,
        x:0,
        y:window.pageYOffset
      }).then(function(canvas) {
        let data = canvas.toDataURL("image/jpeg", 1);
        console.log(data)
      });

 

Logo

助力广东及东莞地区开发者,代码托管、在线学习与竞赛、技术交流与分享、资源共享、职业发展,成为松山湖开发者首选的工作与学习平台

更多推荐