admin管理员组文章数量:1425924
I'm using html2canvas library to take a screenshot of a HTML Node, but it simply doesnt recognize the clip-path
property.
(i'm getting cross-origin issue trying to replicate the error here, so i made a jsfiddle)
/
<div id="root">
<div class="star-mask">
<div class="square"></div>
</div>
</div>
<button onclick="capture()">Capture</button>
.star-mask {
clip-path: path('m55,237 74-228 74,228L9,96h240');
}
.square {
background-color: red;
width: 200px;
height: 150px
}
function capture() {
let node = document.querySelector('.star-mask')
html2canvas(node)
.then(canvas => {
document.querySelector('#root').appendChild(canvas)
})
}
Every time i click on "Capture" the canvas screenshot pletely ignores the clip-path
of the star shape and display only the red square. I already tried html2image library and got the same issue.
There is some other solution that can solve this issue? Or is currently impossible to capture the clip-path
property using JavaScript?
I'm using html2canvas library to take a screenshot of a HTML Node, but it simply doesnt recognize the clip-path
property.
(i'm getting cross-origin issue trying to replicate the error here, so i made a jsfiddle)
https://jsfiddle/1Ly9wn6k/
<div id="root">
<div class="star-mask">
<div class="square"></div>
</div>
</div>
<button onclick="capture()">Capture</button>
.star-mask {
clip-path: path('m55,237 74-228 74,228L9,96h240');
}
.square {
background-color: red;
width: 200px;
height: 150px
}
function capture() {
let node = document.querySelector('.star-mask')
html2canvas(node)
.then(canvas => {
document.querySelector('#root').appendChild(canvas)
})
}
Every time i click on "Capture" the canvas screenshot pletely ignores the clip-path
of the star shape and display only the red square. I already tried html2image library and got the same issue.
There is some other solution that can solve this issue? Or is currently impossible to capture the clip-path
property using JavaScript?
- 1 This is currently not implemented yet so there is nothing you can do now to fix that with that library. Here is the issue. – johannchopin Commented Apr 30, 2021 at 11:20
2 Answers
Reset to default 5 +100Using dom-to-image works for me
function capture() {
let node = document.querySelector('.star-mask')
domtoimage.toPng(node)
.then(dataUrl => {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
}
.star-mask {
clip-path: path('m55,237 74-228 74,228L9,96h240');
}
.square {
background-color: red;
width: 200px;
height: 150px
}
<script src="https://cdnjs.cloudflare./ajax/libs/dom-to-image/2.6.0/dom-to-image.js"></script>
<div id="root">
<div class="star-mask">
<div class="square"></div>
</div>
</div>
<button onclick="capture()">Capture</button>
Check out html-to-image
var node = document.getElementById('my-node');
htmlToImage.toPng(node)
.then(function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
(from https://www.npmjs./package/html-to-image).
本文标签:
版权声明:本文标题:javascript - How to take a screenshot of HTML Node with clip-path CSS property? (html2canvas not working for this) - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745426055a2658117.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论