๋ช ๊ฐ์ง ์์์ ํธ๋ฆฌํ data-html2canvas-ignore
ํ๊ทธ๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง Firefox์์ ์ฌ๋ฐฑ์ด ์์ ์ธ ์์์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. data-html2canvas-style="margin-left: 0"
์ ๊ฐ์ ํน์ ์์์ ๋ํ html2canvas ์ ์ฉ ์คํ์ผ ํ๊ทธ๋ฅผ ์ถ๊ฐํ๊ณ ์ถ์ต๋๋ค.
๋ค๋ฅธ ์ฌ๋์ด ์ด๋ฐ ์ผ์ํ๋ ๋ฐ ํ์ด์ด ์์๋์?
onclone
์ต์
์ผ๋ก ๋ ๋๋ง ๋ ๋ฌธ์ (์๋ณธ์ ๋ณต์ ๋ณธ)์ ๋ด์ฉ์ ์์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
html2canvas(document.body, {onclone: function(document) {
document.querySelector('.something').style.marginLeft = 0;
}}).then(...)
๊ณ ๋ง์ Nik! ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์์ ํด ์ฃผ์ ์ ๋๋จํ ๊ฐ์ฌํฉ๋๋ค. ๋ฌธ์์ ์์ต๋๊น?
์๋์, ์ํ๊น๊ฒ๋ ์๋๋๋ค. ๋ฌธ์๋ ํ์ฌ ๋ง์ ์ธก๋ฉด์์ ํฌ๊ฒ ๋ถ์กฑํฉ๋๋ค ...
๋ค์ด๋ก๋ ํ ์ด๋ฏธ์ง๊ฐ ์ ์ ํ ์คํ์ผ์ ์ป์ง ๋ชปํ๋ฏ๋ก ๋ชจ๋ ์คํ์ผ์ ์ธ๋ผ์ธ CSS๋ก ๋ณํํ์ฌ ์ฌ๋ฐ๋ฅด๊ฒ ๋ ๋๋งํ๊ธฐ ์ํด computed-style-to-inline-style ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ๋ฌธ์ ๋ ๊ทธ๊ฒ์ด ์๋ ๋์ ์ํฅ์ ๋ฏธ์น๊ณ ์๋ค๋ ๊ฒ์ ๋๋ค. ๋ฐ๋ผ์ onclone ํจ์ ๋ด์์ ๋์ ๋ณต์ ๋ ์์์ ๋ํด ์ํํ๊ณ ์ถ์ง๋ง ์๋ํ์ง ์๊ณ ์ด๋ฏธ์ง ์คํ์ผ์ด ์ ์ ํ์ง ์์ต๋๋ค. ์ ๊ทธ๋ฐ์ง ์์ญ๋๊น?
๋๋ ๋๊ฐ์ ์ผ์ ์๋ํ๋ค. ์ฌ๊ธฐ์ ๋ด๊ฐ ๊ทธ๊ฒ์ ๊ตฌํํ๊ณ ๋ชจ๋ ์คํ์ผ์ด ์ ๋๋ก ๋ค์ด๋ก๋ ๋ ๋ฐฉ๋ฒ์ด์๋ค.
const computedStyleToInlineStyle = require("computed-style-to-inline-style");
html2canvas(document.querySelector(".someclass"), {onclone: function(document) {
computedStyleToInlineStyle(document.querySelector(".someclass"), {
recursive: true
});
}}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
...
});
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
onclone
์ต์ ์ผ๋ก ๋ ๋๋ง ๋ ๋ฌธ์ (์๋ณธ์ ๋ณต์ ๋ณธ)์ ๋ด์ฉ์ ์์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.