getElementByID๋ฅผ ์ฌ์ฉํ์ฌ ํน์ ์์๋ง ์บ๋ฒ์ค์ ์ธ์ํ ์ ์์ต๋๊น?
์ต์ ๋ฒ์ ์ ์ฌ์ฉํ๋ฉด document.body์์๋ง ์๋ํฉ๋๋ค.
$("#myButton").click(function () {
html2canvas(document.getElementById('myTable'), {
allowTaint: true,
imageTimeout: 15000,
logging: true,
useCORS: true
}).then(function (canvas) {
document.body.appendChild(canvas);
const b64 = canvas.toDataURL("image/png").replace(/.*,/, '');
console.log("data:image/png;base64, " + b64)
});
});
์์๊ฐ ์ ๋๋ ์๋๋ก ์คํฌ๋กค๋์์ ์ ์์ต๋๋ค. scrollX: -window.scrollX ๋ฐ scrollY: -window.scrollY๋ฅผ ์ถ๊ฐํ์ฌ ์๋ํ์ญ์์ค.
$("#myButton").click(function () {
html2canvas(document.getElementById('myTable'), {
allowTaint: true,
imageTimeout: 15000,
logging: true,
useCORS: true,
scrollX: -window.scrollX,
scrollY: -window.scrollY
}).then(function (canvas) {
document.body.appendChild(canvas);
const b64 = canvas.toDataURL("image/png").replace(/.*,/, '');
console.log("data:image/png;base64, " + b64)
});
});
์๋ฒฝํฉ๋๋ค. ๋๋ถ์ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
์คํฌ๋ฆฐ์ท์ ์ฐ์ ๋ ์คํฌ๋กค์ ์์ฃผ ๋ด๋ฆฌ๋ ๊ฒ์ ๋ฐ๋ผ ์ด ๋ ๊ฐ์ง ์์ฑ์ ๋ฉ์ธ ์์ ์ ์ ์ด์ฃผ์ธ์. ์์ ์๊ฒฌ์ ์ฐธ์กฐํ์ญ์์ค. https://github.com/niklasvh/html2canvas/issues/2368#issuecomment -701920277
scrollX: -window.scrollX,
scrollY: -window.scrollY
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์๊ฐ ์ ๋๋ ์๋๋ก ์คํฌ๋กค๋์์ ์ ์์ต๋๋ค. scrollX: -window.scrollX ๋ฐ scrollY: -window.scrollY๋ฅผ ์ถ๊ฐํ์ฌ ์๋ํ์ญ์์ค.